|
-
December 7th, 2009, 02:11 PM
#1
Problem with Swing -.-
Hey guys,
i have a simple question.
i have a JLabel jlbl_status in which i want so show the status of the current process.
if i set the text with the setText() method the text is not displayed in that moment.
It will be displayed after the whole action...
for example:
i have a JButton which trigges the following
Code:
log.info("recalculate Values");
RecalculateTableValuesJob job;
try {
job = new RecalculateTableValuesJob();
}catch(Exception e){
log.error("Cant start the recalc. job");
e.printStackTrace();
return;
}
setStatus("Calculation...");
setProgress(0);
job.start();
while(job.isRunning){
try{Thread.sleep(1000); }catch(Exception e){}
int p = (int)(100*xlsData.getRowCount()/job.currentIndex);
setProgress(p);
}
setProgress(100);
log.info("recalculate Values Done");
btw. i also have the same problem with my JProgressBar ;-)
my setStatus looks like
Code:
public void setStatus(String text) {
log.debug("Status: "+text);
jlbl_status.setText(text);
}
i have tried also with
jlbl_status.invalidate();
jlbl_status.revalidate();
jlbl_status.repaint();
so PLEASE!! help me... why doesnt my JLabel repaint synchronously?
-
December 8th, 2009, 03:40 AM
#2
Re: Problem with Swing -.-
hey i found out, that when i do this action in my init of the program everything works fine.
So it has something to do with my buttonevent?!
Cuz only then it doent work -.-...
-
December 8th, 2009, 06:24 AM
#3
Re: Problem with Swing -.-
You need to update your label text in the Swing Event dispatch Thread (EDT), not directly from your calculation thread. Swing provides a SwingWorker class you should use for background work that makes updating Swing components on the EDT very simple.
See Concurrency In Swing for a full explanation & tutorial, with examples.
It is a bad plan that admits of no modification...
P. Syrus
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
December 8th, 2009, 01:28 PM
#4
Re: Problem with Swing -.-
It works!! =)
You are a god ^^ why havn't i heard of this before?!...
Well, thanks dlorde
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|