Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
I am developing a simple program to add 2 numbers. It contains 2 TextFields and 1 Button. When clicked on button, button handler will add 2 numbers in text fields and puts it in label, add it to the panel. (All components are panel, and panel is added to the frame.)
The problem is that after adding the label to the panel, I am calling repaint method on panel, or frame not updating the GUI. But, when I resize the window with mouse, it updating. If hiding the panel, or frame by using setVisible and making it visible again updating the GUI.
But, I didn't understand why repaint is not updating the GUI?
AnswerBot
Question subject: Re: Swing: repaint and setVisible
Posted: Thu Oct 23, 2008 12:40 am
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
It's been a while since I worked in Swing, but this is what I remember:
You can't call repaint () from the code handling your request. This is the Swing dispatch thread. Instead, use invokeAndWait or invokeLater (I would advise invokeLater, because it runs the repaint process asynchronously). See Java's JavaDoc of the SwingUtilities class: http://java.sun.com/j2se/1.5.0/docs/api ... ities.html