Update JProgressbar in JTable if JCheckbox is checked
up vote
0
down vote
favorite
I have problem with updating progressbar. If I check checkbox, file is automaticaly copied but progress is still 0. I use SwingWokrer, but I don't know how I can progressbar updating.
I tried many combinations, but it does not work.
This code is responsible for downloading the file from the selected row.
jTable.getModel().addTableModelListener(new TableModelListener()
public void tableChanged(TableModelEvent e)
int row = e.getFirstRow();
int column = e.getColumn();
TableModel tableModel = (TableModel) e.getSource();
Boolean dataObject = (Boolean) tableModel.getValueAt(row,column);
String fileNameToCopy = (String) tableModel.getValueAt(row, 0);
Long fileSize = (Long) tableModel.getValueAt(row, 1);
Float progress = (Float) tableModel.getValueAt(row, 3);
if (dataObject == true)
customTableData.setFile(new File(fileNameToCopy));
customTableData.setFileSize(fileSize);
customTableData.setProgress(progress);;
copyFiles = new CopyFiles(customTableData);
);
CustomTableData.java
public class CustomTableData
private File file;
private long fileSize;
private Boolean edit = false;
private float progress;
public CustomTableData()
public File getFile()
return file;
public void setFile(File file)
this.file = file;
public long getFileSize()
return fileSize;
public void setFileSize(long fileSize)
this.fileSize = fileSize;
public Boolean isEdit()
return edit;
public void setEdit(Boolean edit)
this.edit = edit;
public float getProgress()
return progress;
public void setProgress(float progress)
this.progress = progress;
My CopyFiles.java class
private String fileName;
private long fileSize;
private float progress;
private CustomTableData data;
public CopyFiles(CustomTableData data)
this.data = new CustomTableData();
this.fileName = data.getFile().getName();
this.fileSize = data.getFileSize();
this.progress = data.getProgress();
worker.execute();
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
try
is = new FileInputStream(source + fileName);
os = new FileOutputStream(destination + fileName);
byte buffer = new byte[BUFFER];
int length = 0;
float pro = 0;
while((length = is.read(buffer)) != -1)
publish(pro += length);
os.write(buffer, 0, length);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(java.util.List<Float> chunks)
for (Float f : chunks)
progress = (f*100) / fileSize;
System.out.println("Percentage progress: " + progress + " >>> file size: " + f);
;
protected void done()
System.out.println("FILE: " + fileName + " SIZE: " + fileSize);
;
;
}
And my CustomTableModel.java class
public class CustomTableModel extends AbstractTableModel
private static final long serialVersionUID = -2929662905556163705L;
@SuppressWarnings("unused")
private File dir;
private File fileArray;
private List<CustomTableData> filesList;
private CustomTableData fileRow;
public CustomTableModel(File dir)
this.dir = dir;
this.filesList = new ArrayList<CustomTableData>();
this.fileArray = dir.listFiles();
fileLoop();
private void fileLoop()
for (int i = 0; i < fileArray.length; i++)
this.fileRow = new CustomTableData();
if (fileArray[i].isFile())
fileRow.setFile(fileArray[i]);
fileRow.isEdit();
fileRow.getProgress();
filesList.add(fileRow);
private ResourceBundle resourceBundle = ResourceBundle.getBundle("MessageBundle", Locale.forLanguageTag("pl"));
protected String columns = new String
resourceBundle.getString("fileName"),
resourceBundle.getString("fileSize") + " [byte]",
resourceBundle.getString("getFile"),
resourceBundle.getString("progress");
@SuppressWarnings("rawtypes")
protected Class columnClasses = String.class , Long.class, JCheckBox.class, JProgressBar.class;
public int getColumnCount()
return columns.length;
public int getRowCount()
return filesList.size();
public String getColumnName(int col)
return columns[col].toString();
public Class<?> getColumnClass(int c)
switch (c)
case 0:
return String.class;
case 1:
return Long.class;
case 2:
return Boolean.class;
case 3:
return Float.class;
default:
return null;
public Object getValueAt(int row, int col)
fileRow = filesList.get(row);
switch (col)
case 0:
return fileRow.getFile().getName();
case 1:
return fileRow.getFile().length();
case 2:
return fileRow.isEdit();
case 3:
return fileRow.getProgress();
default:
return null;
public boolean isCellEditable(int row, int col)
switch (col)
case 0:
return false;
case 1:
return false;
case 2:
return true;
case 3:
return false;
default:
return false;
public void setValueAt(Object aValue, int row, int column)
fileRow = filesList.get(row);
if (column == 2)
fileRow.setEdit((Boolean)aValue);
fireTableCellUpdated(row, column);
This is my ProgressBarRenderer.java class
public class ProgressBarRenderer extends JProgressBar implements TableCellRenderer
private static final long serialVersionUID = 551156559687881082L;
public ProgressBarRenderer()
super();
public ProgressBarRenderer(int min, int max)
super(min, max);
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
setValue((int) ((Float) value).floatValue());
return this;
My table view
java swing jtable swingworker jprogressbar
add a comment |
up vote
0
down vote
favorite
I have problem with updating progressbar. If I check checkbox, file is automaticaly copied but progress is still 0. I use SwingWokrer, but I don't know how I can progressbar updating.
I tried many combinations, but it does not work.
This code is responsible for downloading the file from the selected row.
jTable.getModel().addTableModelListener(new TableModelListener()
public void tableChanged(TableModelEvent e)
int row = e.getFirstRow();
int column = e.getColumn();
TableModel tableModel = (TableModel) e.getSource();
Boolean dataObject = (Boolean) tableModel.getValueAt(row,column);
String fileNameToCopy = (String) tableModel.getValueAt(row, 0);
Long fileSize = (Long) tableModel.getValueAt(row, 1);
Float progress = (Float) tableModel.getValueAt(row, 3);
if (dataObject == true)
customTableData.setFile(new File(fileNameToCopy));
customTableData.setFileSize(fileSize);
customTableData.setProgress(progress);;
copyFiles = new CopyFiles(customTableData);
);
CustomTableData.java
public class CustomTableData
private File file;
private long fileSize;
private Boolean edit = false;
private float progress;
public CustomTableData()
public File getFile()
return file;
public void setFile(File file)
this.file = file;
public long getFileSize()
return fileSize;
public void setFileSize(long fileSize)
this.fileSize = fileSize;
public Boolean isEdit()
return edit;
public void setEdit(Boolean edit)
this.edit = edit;
public float getProgress()
return progress;
public void setProgress(float progress)
this.progress = progress;
My CopyFiles.java class
private String fileName;
private long fileSize;
private float progress;
private CustomTableData data;
public CopyFiles(CustomTableData data)
this.data = new CustomTableData();
this.fileName = data.getFile().getName();
this.fileSize = data.getFileSize();
this.progress = data.getProgress();
worker.execute();
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
try
is = new FileInputStream(source + fileName);
os = new FileOutputStream(destination + fileName);
byte buffer = new byte[BUFFER];
int length = 0;
float pro = 0;
while((length = is.read(buffer)) != -1)
publish(pro += length);
os.write(buffer, 0, length);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(java.util.List<Float> chunks)
for (Float f : chunks)
progress = (f*100) / fileSize;
System.out.println("Percentage progress: " + progress + " >>> file size: " + f);
;
protected void done()
System.out.println("FILE: " + fileName + " SIZE: " + fileSize);
;
;
}
And my CustomTableModel.java class
public class CustomTableModel extends AbstractTableModel
private static final long serialVersionUID = -2929662905556163705L;
@SuppressWarnings("unused")
private File dir;
private File fileArray;
private List<CustomTableData> filesList;
private CustomTableData fileRow;
public CustomTableModel(File dir)
this.dir = dir;
this.filesList = new ArrayList<CustomTableData>();
this.fileArray = dir.listFiles();
fileLoop();
private void fileLoop()
for (int i = 0; i < fileArray.length; i++)
this.fileRow = new CustomTableData();
if (fileArray[i].isFile())
fileRow.setFile(fileArray[i]);
fileRow.isEdit();
fileRow.getProgress();
filesList.add(fileRow);
private ResourceBundle resourceBundle = ResourceBundle.getBundle("MessageBundle", Locale.forLanguageTag("pl"));
protected String columns = new String
resourceBundle.getString("fileName"),
resourceBundle.getString("fileSize") + " [byte]",
resourceBundle.getString("getFile"),
resourceBundle.getString("progress");
@SuppressWarnings("rawtypes")
protected Class columnClasses = String.class , Long.class, JCheckBox.class, JProgressBar.class;
public int getColumnCount()
return columns.length;
public int getRowCount()
return filesList.size();
public String getColumnName(int col)
return columns[col].toString();
public Class<?> getColumnClass(int c)
switch (c)
case 0:
return String.class;
case 1:
return Long.class;
case 2:
return Boolean.class;
case 3:
return Float.class;
default:
return null;
public Object getValueAt(int row, int col)
fileRow = filesList.get(row);
switch (col)
case 0:
return fileRow.getFile().getName();
case 1:
return fileRow.getFile().length();
case 2:
return fileRow.isEdit();
case 3:
return fileRow.getProgress();
default:
return null;
public boolean isCellEditable(int row, int col)
switch (col)
case 0:
return false;
case 1:
return false;
case 2:
return true;
case 3:
return false;
default:
return false;
public void setValueAt(Object aValue, int row, int column)
fileRow = filesList.get(row);
if (column == 2)
fileRow.setEdit((Boolean)aValue);
fireTableCellUpdated(row, column);
This is my ProgressBarRenderer.java class
public class ProgressBarRenderer extends JProgressBar implements TableCellRenderer
private static final long serialVersionUID = 551156559687881082L;
public ProgressBarRenderer()
super();
public ProgressBarRenderer(int min, int max)
super(min, max);
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
setValue((int) ((Float) value).floatValue());
return this;
My table view
java swing jtable swingworker jprogressbar
1
Does yourprocess()
logic display the proper values? If so then that is where you need to update your table with the new value so the progress bar can be repainted.
– camickr
Oct 31 at 14:35
Yes value is correct 0 to 100 (%). But my table don't see changes...
– PrzemekC
Nov 2 at 9:29
But my table don't see changes...
- because you don't change the data in the table. All you do is display a message. That is the code where you need to invoke table.setValueAt(...) to update the data in the table so the new value can be displayed.
– camickr
Nov 2 at 14:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have problem with updating progressbar. If I check checkbox, file is automaticaly copied but progress is still 0. I use SwingWokrer, but I don't know how I can progressbar updating.
I tried many combinations, but it does not work.
This code is responsible for downloading the file from the selected row.
jTable.getModel().addTableModelListener(new TableModelListener()
public void tableChanged(TableModelEvent e)
int row = e.getFirstRow();
int column = e.getColumn();
TableModel tableModel = (TableModel) e.getSource();
Boolean dataObject = (Boolean) tableModel.getValueAt(row,column);
String fileNameToCopy = (String) tableModel.getValueAt(row, 0);
Long fileSize = (Long) tableModel.getValueAt(row, 1);
Float progress = (Float) tableModel.getValueAt(row, 3);
if (dataObject == true)
customTableData.setFile(new File(fileNameToCopy));
customTableData.setFileSize(fileSize);
customTableData.setProgress(progress);;
copyFiles = new CopyFiles(customTableData);
);
CustomTableData.java
public class CustomTableData
private File file;
private long fileSize;
private Boolean edit = false;
private float progress;
public CustomTableData()
public File getFile()
return file;
public void setFile(File file)
this.file = file;
public long getFileSize()
return fileSize;
public void setFileSize(long fileSize)
this.fileSize = fileSize;
public Boolean isEdit()
return edit;
public void setEdit(Boolean edit)
this.edit = edit;
public float getProgress()
return progress;
public void setProgress(float progress)
this.progress = progress;
My CopyFiles.java class
private String fileName;
private long fileSize;
private float progress;
private CustomTableData data;
public CopyFiles(CustomTableData data)
this.data = new CustomTableData();
this.fileName = data.getFile().getName();
this.fileSize = data.getFileSize();
this.progress = data.getProgress();
worker.execute();
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
try
is = new FileInputStream(source + fileName);
os = new FileOutputStream(destination + fileName);
byte buffer = new byte[BUFFER];
int length = 0;
float pro = 0;
while((length = is.read(buffer)) != -1)
publish(pro += length);
os.write(buffer, 0, length);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(java.util.List<Float> chunks)
for (Float f : chunks)
progress = (f*100) / fileSize;
System.out.println("Percentage progress: " + progress + " >>> file size: " + f);
;
protected void done()
System.out.println("FILE: " + fileName + " SIZE: " + fileSize);
;
;
}
And my CustomTableModel.java class
public class CustomTableModel extends AbstractTableModel
private static final long serialVersionUID = -2929662905556163705L;
@SuppressWarnings("unused")
private File dir;
private File fileArray;
private List<CustomTableData> filesList;
private CustomTableData fileRow;
public CustomTableModel(File dir)
this.dir = dir;
this.filesList = new ArrayList<CustomTableData>();
this.fileArray = dir.listFiles();
fileLoop();
private void fileLoop()
for (int i = 0; i < fileArray.length; i++)
this.fileRow = new CustomTableData();
if (fileArray[i].isFile())
fileRow.setFile(fileArray[i]);
fileRow.isEdit();
fileRow.getProgress();
filesList.add(fileRow);
private ResourceBundle resourceBundle = ResourceBundle.getBundle("MessageBundle", Locale.forLanguageTag("pl"));
protected String columns = new String
resourceBundle.getString("fileName"),
resourceBundle.getString("fileSize") + " [byte]",
resourceBundle.getString("getFile"),
resourceBundle.getString("progress");
@SuppressWarnings("rawtypes")
protected Class columnClasses = String.class , Long.class, JCheckBox.class, JProgressBar.class;
public int getColumnCount()
return columns.length;
public int getRowCount()
return filesList.size();
public String getColumnName(int col)
return columns[col].toString();
public Class<?> getColumnClass(int c)
switch (c)
case 0:
return String.class;
case 1:
return Long.class;
case 2:
return Boolean.class;
case 3:
return Float.class;
default:
return null;
public Object getValueAt(int row, int col)
fileRow = filesList.get(row);
switch (col)
case 0:
return fileRow.getFile().getName();
case 1:
return fileRow.getFile().length();
case 2:
return fileRow.isEdit();
case 3:
return fileRow.getProgress();
default:
return null;
public boolean isCellEditable(int row, int col)
switch (col)
case 0:
return false;
case 1:
return false;
case 2:
return true;
case 3:
return false;
default:
return false;
public void setValueAt(Object aValue, int row, int column)
fileRow = filesList.get(row);
if (column == 2)
fileRow.setEdit((Boolean)aValue);
fireTableCellUpdated(row, column);
This is my ProgressBarRenderer.java class
public class ProgressBarRenderer extends JProgressBar implements TableCellRenderer
private static final long serialVersionUID = 551156559687881082L;
public ProgressBarRenderer()
super();
public ProgressBarRenderer(int min, int max)
super(min, max);
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
setValue((int) ((Float) value).floatValue());
return this;
My table view
java swing jtable swingworker jprogressbar
I have problem with updating progressbar. If I check checkbox, file is automaticaly copied but progress is still 0. I use SwingWokrer, but I don't know how I can progressbar updating.
I tried many combinations, but it does not work.
This code is responsible for downloading the file from the selected row.
jTable.getModel().addTableModelListener(new TableModelListener()
public void tableChanged(TableModelEvent e)
int row = e.getFirstRow();
int column = e.getColumn();
TableModel tableModel = (TableModel) e.getSource();
Boolean dataObject = (Boolean) tableModel.getValueAt(row,column);
String fileNameToCopy = (String) tableModel.getValueAt(row, 0);
Long fileSize = (Long) tableModel.getValueAt(row, 1);
Float progress = (Float) tableModel.getValueAt(row, 3);
if (dataObject == true)
customTableData.setFile(new File(fileNameToCopy));
customTableData.setFileSize(fileSize);
customTableData.setProgress(progress);;
copyFiles = new CopyFiles(customTableData);
);
CustomTableData.java
public class CustomTableData
private File file;
private long fileSize;
private Boolean edit = false;
private float progress;
public CustomTableData()
public File getFile()
return file;
public void setFile(File file)
this.file = file;
public long getFileSize()
return fileSize;
public void setFileSize(long fileSize)
this.fileSize = fileSize;
public Boolean isEdit()
return edit;
public void setEdit(Boolean edit)
this.edit = edit;
public float getProgress()
return progress;
public void setProgress(float progress)
this.progress = progress;
My CopyFiles.java class
private String fileName;
private long fileSize;
private float progress;
private CustomTableData data;
public CopyFiles(CustomTableData data)
this.data = new CustomTableData();
this.fileName = data.getFile().getName();
this.fileSize = data.getFileSize();
this.progress = data.getProgress();
worker.execute();
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
try
is = new FileInputStream(source + fileName);
os = new FileOutputStream(destination + fileName);
byte buffer = new byte[BUFFER];
int length = 0;
float pro = 0;
while((length = is.read(buffer)) != -1)
publish(pro += length);
os.write(buffer, 0, length);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(java.util.List<Float> chunks)
for (Float f : chunks)
progress = (f*100) / fileSize;
System.out.println("Percentage progress: " + progress + " >>> file size: " + f);
;
protected void done()
System.out.println("FILE: " + fileName + " SIZE: " + fileSize);
;
;
}
And my CustomTableModel.java class
public class CustomTableModel extends AbstractTableModel
private static final long serialVersionUID = -2929662905556163705L;
@SuppressWarnings("unused")
private File dir;
private File fileArray;
private List<CustomTableData> filesList;
private CustomTableData fileRow;
public CustomTableModel(File dir)
this.dir = dir;
this.filesList = new ArrayList<CustomTableData>();
this.fileArray = dir.listFiles();
fileLoop();
private void fileLoop()
for (int i = 0; i < fileArray.length; i++)
this.fileRow = new CustomTableData();
if (fileArray[i].isFile())
fileRow.setFile(fileArray[i]);
fileRow.isEdit();
fileRow.getProgress();
filesList.add(fileRow);
private ResourceBundle resourceBundle = ResourceBundle.getBundle("MessageBundle", Locale.forLanguageTag("pl"));
protected String columns = new String
resourceBundle.getString("fileName"),
resourceBundle.getString("fileSize") + " [byte]",
resourceBundle.getString("getFile"),
resourceBundle.getString("progress");
@SuppressWarnings("rawtypes")
protected Class columnClasses = String.class , Long.class, JCheckBox.class, JProgressBar.class;
public int getColumnCount()
return columns.length;
public int getRowCount()
return filesList.size();
public String getColumnName(int col)
return columns[col].toString();
public Class<?> getColumnClass(int c)
switch (c)
case 0:
return String.class;
case 1:
return Long.class;
case 2:
return Boolean.class;
case 3:
return Float.class;
default:
return null;
public Object getValueAt(int row, int col)
fileRow = filesList.get(row);
switch (col)
case 0:
return fileRow.getFile().getName();
case 1:
return fileRow.getFile().length();
case 2:
return fileRow.isEdit();
case 3:
return fileRow.getProgress();
default:
return null;
public boolean isCellEditable(int row, int col)
switch (col)
case 0:
return false;
case 1:
return false;
case 2:
return true;
case 3:
return false;
default:
return false;
public void setValueAt(Object aValue, int row, int column)
fileRow = filesList.get(row);
if (column == 2)
fileRow.setEdit((Boolean)aValue);
fireTableCellUpdated(row, column);
This is my ProgressBarRenderer.java class
public class ProgressBarRenderer extends JProgressBar implements TableCellRenderer
private static final long serialVersionUID = 551156559687881082L;
public ProgressBarRenderer()
super();
public ProgressBarRenderer(int min, int max)
super(min, max);
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
setValue((int) ((Float) value).floatValue());
return this;
My table view
java swing jtable swingworker jprogressbar
java swing jtable swingworker jprogressbar
edited Oct 31 at 10:50
asked Oct 31 at 9:22
PrzemekC
813
813
1
Does yourprocess()
logic display the proper values? If so then that is where you need to update your table with the new value so the progress bar can be repainted.
– camickr
Oct 31 at 14:35
Yes value is correct 0 to 100 (%). But my table don't see changes...
– PrzemekC
Nov 2 at 9:29
But my table don't see changes...
- because you don't change the data in the table. All you do is display a message. That is the code where you need to invoke table.setValueAt(...) to update the data in the table so the new value can be displayed.
– camickr
Nov 2 at 14:29
add a comment |
1
Does yourprocess()
logic display the proper values? If so then that is where you need to update your table with the new value so the progress bar can be repainted.
– camickr
Oct 31 at 14:35
Yes value is correct 0 to 100 (%). But my table don't see changes...
– PrzemekC
Nov 2 at 9:29
But my table don't see changes...
- because you don't change the data in the table. All you do is display a message. That is the code where you need to invoke table.setValueAt(...) to update the data in the table so the new value can be displayed.
– camickr
Nov 2 at 14:29
1
1
Does your
process()
logic display the proper values? If so then that is where you need to update your table with the new value so the progress bar can be repainted.– camickr
Oct 31 at 14:35
Does your
process()
logic display the proper values? If so then that is where you need to update your table with the new value so the progress bar can be repainted.– camickr
Oct 31 at 14:35
Yes value is correct 0 to 100 (%). But my table don't see changes...
– PrzemekC
Nov 2 at 9:29
Yes value is correct 0 to 100 (%). But my table don't see changes...
– PrzemekC
Nov 2 at 9:29
But my table don't see changes...
- because you don't change the data in the table. All you do is display a message. That is the code where you need to invoke table.setValueAt(...) to update the data in the table so the new value can be displayed.– camickr
Nov 2 at 14:29
But my table don't see changes...
- because you don't change the data in the table. All you do is display a message. That is the code where you need to invoke table.setValueAt(...) to update the data in the table so the new value can be displayed.– camickr
Nov 2 at 14:29
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Rozwiązanie
Progressbar jest prawidłowo aktualizowany w metodzie process()
public class CopyFiles {
private static final int BUFFER = 1024;
private int row;
private CustomTableModel customTableModel;
private String fileName;
private File file;
public CopyFiles(String fileName, CustomTableModel customTableModel, int row)
this.fileName = fileName;
this.file = new File(PathEnum.SOURCE.getPath() + fileName);
this.customTableModel = customTableModel;
this.row = row;
worker.execute();
public String getFile()
return file.getName();
public long getFileSize()
return file.length();
public SwingWorker<Void, Float> getWorker()
return worker;
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
float progress = 0;
try
is = new FileInputStream(PathEnum.SOURCE.getPath() + getFile());
os = new FileOutputStream(PathEnum.DESTINATION.getPath() + getFile());
byte buffer = new byte[BUFFER];
long count = 0;
int bufferLength;
while ((bufferLength = is.read(buffer)) != -1)
count += bufferLength;
os.write(buffer, 0, bufferLength);
progress = (int) ((count * 100) / getFileSize());
publish(progress);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(List<Float> chunks)
float currentProgress = chunks.get(chunks.size()-1);
customTableModel.setValueAt(currentProgress, row, 3);
;
protected void done()
System.out.println("FILE: " + getFile() + " SIZE: " + getFileSize());
;
;
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Rozwiązanie
Progressbar jest prawidłowo aktualizowany w metodzie process()
public class CopyFiles {
private static final int BUFFER = 1024;
private int row;
private CustomTableModel customTableModel;
private String fileName;
private File file;
public CopyFiles(String fileName, CustomTableModel customTableModel, int row)
this.fileName = fileName;
this.file = new File(PathEnum.SOURCE.getPath() + fileName);
this.customTableModel = customTableModel;
this.row = row;
worker.execute();
public String getFile()
return file.getName();
public long getFileSize()
return file.length();
public SwingWorker<Void, Float> getWorker()
return worker;
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
float progress = 0;
try
is = new FileInputStream(PathEnum.SOURCE.getPath() + getFile());
os = new FileOutputStream(PathEnum.DESTINATION.getPath() + getFile());
byte buffer = new byte[BUFFER];
long count = 0;
int bufferLength;
while ((bufferLength = is.read(buffer)) != -1)
count += bufferLength;
os.write(buffer, 0, bufferLength);
progress = (int) ((count * 100) / getFileSize());
publish(progress);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(List<Float> chunks)
float currentProgress = chunks.get(chunks.size()-1);
customTableModel.setValueAt(currentProgress, row, 3);
;
protected void done()
System.out.println("FILE: " + getFile() + " SIZE: " + getFileSize());
;
;
add a comment |
up vote
0
down vote
Rozwiązanie
Progressbar jest prawidłowo aktualizowany w metodzie process()
public class CopyFiles {
private static final int BUFFER = 1024;
private int row;
private CustomTableModel customTableModel;
private String fileName;
private File file;
public CopyFiles(String fileName, CustomTableModel customTableModel, int row)
this.fileName = fileName;
this.file = new File(PathEnum.SOURCE.getPath() + fileName);
this.customTableModel = customTableModel;
this.row = row;
worker.execute();
public String getFile()
return file.getName();
public long getFileSize()
return file.length();
public SwingWorker<Void, Float> getWorker()
return worker;
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
float progress = 0;
try
is = new FileInputStream(PathEnum.SOURCE.getPath() + getFile());
os = new FileOutputStream(PathEnum.DESTINATION.getPath() + getFile());
byte buffer = new byte[BUFFER];
long count = 0;
int bufferLength;
while ((bufferLength = is.read(buffer)) != -1)
count += bufferLength;
os.write(buffer, 0, bufferLength);
progress = (int) ((count * 100) / getFileSize());
publish(progress);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(List<Float> chunks)
float currentProgress = chunks.get(chunks.size()-1);
customTableModel.setValueAt(currentProgress, row, 3);
;
protected void done()
System.out.println("FILE: " + getFile() + " SIZE: " + getFileSize());
;
;
add a comment |
up vote
0
down vote
up vote
0
down vote
Rozwiązanie
Progressbar jest prawidłowo aktualizowany w metodzie process()
public class CopyFiles {
private static final int BUFFER = 1024;
private int row;
private CustomTableModel customTableModel;
private String fileName;
private File file;
public CopyFiles(String fileName, CustomTableModel customTableModel, int row)
this.fileName = fileName;
this.file = new File(PathEnum.SOURCE.getPath() + fileName);
this.customTableModel = customTableModel;
this.row = row;
worker.execute();
public String getFile()
return file.getName();
public long getFileSize()
return file.length();
public SwingWorker<Void, Float> getWorker()
return worker;
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
float progress = 0;
try
is = new FileInputStream(PathEnum.SOURCE.getPath() + getFile());
os = new FileOutputStream(PathEnum.DESTINATION.getPath() + getFile());
byte buffer = new byte[BUFFER];
long count = 0;
int bufferLength;
while ((bufferLength = is.read(buffer)) != -1)
count += bufferLength;
os.write(buffer, 0, bufferLength);
progress = (int) ((count * 100) / getFileSize());
publish(progress);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(List<Float> chunks)
float currentProgress = chunks.get(chunks.size()-1);
customTableModel.setValueAt(currentProgress, row, 3);
;
protected void done()
System.out.println("FILE: " + getFile() + " SIZE: " + getFileSize());
;
;
Rozwiązanie
Progressbar jest prawidłowo aktualizowany w metodzie process()
public class CopyFiles {
private static final int BUFFER = 1024;
private int row;
private CustomTableModel customTableModel;
private String fileName;
private File file;
public CopyFiles(String fileName, CustomTableModel customTableModel, int row)
this.fileName = fileName;
this.file = new File(PathEnum.SOURCE.getPath() + fileName);
this.customTableModel = customTableModel;
this.row = row;
worker.execute();
public String getFile()
return file.getName();
public long getFileSize()
return file.length();
public SwingWorker<Void, Float> getWorker()
return worker;
SwingWorker<Void, Float> worker = new SwingWorker<Void, Float>()
@Override
protected Void doInBackground() throws Exception
InputStream is = null;
OutputStream os = null;
float progress = 0;
try
is = new FileInputStream(PathEnum.SOURCE.getPath() + getFile());
os = new FileOutputStream(PathEnum.DESTINATION.getPath() + getFile());
byte buffer = new byte[BUFFER];
long count = 0;
int bufferLength;
while ((bufferLength = is.read(buffer)) != -1)
count += bufferLength;
os.write(buffer, 0, bufferLength);
progress = (int) ((count * 100) / getFileSize());
publish(progress);
catch (Exception e)
e.getMessage();
finally
try
is.close();
os.close();
catch (IOException e)
e.getMessage();
return null;
protected void process(List<Float> chunks)
float currentProgress = chunks.get(chunks.size()-1);
customTableModel.setValueAt(currentProgress, row, 3);
;
protected void done()
System.out.println("FILE: " + getFile() + " SIZE: " + getFileSize());
;
;
answered Nov 9 at 15:16
PrzemekC
813
813
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53080044%2fupdate-jprogressbar-in-jtable-if-jcheckbox-is-checked%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Does your
process()
logic display the proper values? If so then that is where you need to update your table with the new value so the progress bar can be repainted.– camickr
Oct 31 at 14:35
Yes value is correct 0 to 100 (%). But my table don't see changes...
– PrzemekC
Nov 2 at 9:29
But my table don't see changes...
- because you don't change the data in the table. All you do is display a message. That is the code where you need to invoke table.setValueAt(...) to update the data in the table so the new value can be displayed.– camickr
Nov 2 at 14:29