Im trying to make a JDialog that will show the user a dynamic message on a JLabel.
The message should be a count from 1 to 10 (and it should be changing a number every second).
the thing is , when im debugging it – it’s stops right after the “dia.setVisible(true);” , and will not proceed unless i will close the JDialog .
is there any possible way of fixing it?
Thanks.
Take a look at the code :
@Override
public void run() {
dia = new JDialog(parentDialog, true);
dia.setLocationRelativeTo(parentFrame);
String text = "Text ";
dia.setSize(300, 150);
jl = new JLabel(text);
dia.getContentPane().add(jl);
dia.setVisible(true);
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
jl.setText(text + " " + i);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
don’t use
Thread.sleep(int)for Swing GUI, caused freeze of untillThread.sleep(int)endeduse
Swing Timerinstead of locking Swing GUI by usage ofThread.sleep(int)don’t use
dia.setSize(300, 150), learn howLayoutManagerworks