Thu Oct 23, 2008 12:39 am
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?
Thu Oct 23, 2008 12:40 am
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.htmlAlso check out the Swing tutorial:
http://java.sun.com/docs/books/tutorial ... index.html
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.