Problems with synchronization in JLabel (and Swing at all)
From: Chrosciu (chrosciu_at_poczta.onet.pl)
Date: 01/27/05
- Next message: Gil: "JTable questions"
- Previous message: Thomas Fritsch: "Re: How can I get a nice border around components?"
- Next in thread: Roland: "Re: Problems with synchronization in JLabel (and Swing at all)"
- Reply: Roland: "Re: Problems with synchronization in JLabel (and Swing at all)"
- Reply: David Segall: "Re: Problems with synchronization in JLabel (and Swing at all)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Jan 2005 04:11:14 -0800
I have written a small program in Java, which performs complicated and
long-lasting calculations. So I want to illustrate the progress of
these calculations by a text (percent work done) placed in JLabel
component. But I have a "small" problem - this text doesn't change
during the calculations and after them it is set at once to 100%. The
source code is as follows :
percent = 0;
for (....)
{
// calculations
percent +=... //small progress value
Label2.setText(Double.toString(percent));
}
I have searched Web and read this can be caused by non-synchronized
threads of GUI and rest of program, but I don't know how it can be
repaired. I've already tried one method (shown below) but it also
doesn't work (effects are the same as in first program):
static void setTextOnLabel(final String text)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
jLabel2.setText(text);
}
});
}
....
percent = 0;
for (....)
{
// calculations
percent +=...
setTextOnLabel(Double.toString(percent));
}
Can anyone help me? Thanks in advance
Chrosciu
- Next message: Gil: "JTable questions"
- Previous message: Thomas Fritsch: "Re: How can I get a nice border around components?"
- Next in thread: Roland: "Re: Problems with synchronization in JLabel (and Swing at all)"
- Reply: Roland: "Re: Problems with synchronization in JLabel (and Swing at all)"
- Reply: David Segall: "Re: Problems with synchronization in JLabel (and Swing at all)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|