JTable row selection Problem
I am facing a problem with JTable.
This what I'm doing...
I'm designing a downloader application. Which maintain a queue of downloads in JTable. For each download there will be thread created and these thread will update the table as download proceed. (No. of bytes updated or status of the download).
So I have a option which will allow me to pause a particular download.
So I have a pause Button. If a user click a particular download (by selecting a row in JTable) and if the download is already done, then Pause button has to be disable. But my problem is when ever i click the JTable button the rowselected index is -1. But when no thread is updating the JTable i'm getting the correct rowselected value.
try{
while(status==1){
//System.out.println(">>" + Utilities.compareToCurrentTime(stuff.eDate));
read_at_single = fin.read(b,0,1024);
//System.out.println(read_at_single);
if(read_at_single<0){// last packet or end
status = 5;
this.stuff.status = Integer.toString(status);
this.stuff.infoMsg ="Completed";
DownloaderGUI.tableModel.fireTableDataChanged();
}else{
if(downloadLimit>0 && total_read+read_at_single>downloadLimit){
//System.out.println("Limit : " + downloadLimit + "; total_read: " + (total_read+read_at_single));
//System.out.println("err:" + (int) (total_read+read_at_single-downloadLimit));
fout.write(b,0,(int) (downloadLimit-total_read));
total_read = total_read + (int) (downloadLimit-total_read);
downloadDone = total_read;
this.stuff.completed = Long.toString(downloadDone);
status = 5;// force completion since downloading
this.stuff.status = Integer.toString(status);
DownloaderGUI.tableModel.fireTableDataChanged();
// only a part of a file...
}elseif(isScheduled && Utilities.compareToCurrentTime(stuff.eDate)<=0){
//System.out.println("Limit : " + downloadLimit + "; total_read: " + (total_read+read_at_single));
//System.out.println("err:" + (int) (total_read+read_at_single-downloadLimit));
fout.write(b,0,read_at_single);
total_read = total_read + read_at_single;
downloadDone = total_read;
this.stuff.completed = Long.toString(downloadDone);
status = 3;// force pause since downloading only on schedule
this.stuff.status = Integer.toString(status);
this.stuff.infoMsg ="Paused:Out of Schedule";
DownloaderGUI.tableModel.fireTableDataChanged();
}
else{
fout.write(b,0,read_at_single);
total_read = total_read + read_at_single;
downloadDone = total_read;
this.stuff.completed = Long.toString(downloadDone);
DownloaderGUI.tableModel.fireTableDataChanged();
}
}
}
This is the code snippet in the downloader thread.
Hope I made by problem clear.
Thanks...

