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










share|improve this question



















  • 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














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










share|improve this question



















  • 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












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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 31 at 10:50

























asked Oct 31 at 9:22









PrzemekC

813




813







  • 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












  • 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







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












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());
;

;





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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());
    ;

    ;





    share|improve this answer
























      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());
      ;

      ;





      share|improve this answer






















        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());
        ;

        ;





        share|improve this answer












        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());
        ;

        ;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 15:16









        PrzemekC

        813




        813



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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














































































            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20