please any body tell, what going when following code at executing time?
SwingUtilities.invokeLater(new Runnable() {
public void run(){
new SwingDemo();
Thanks SIR....
Printable View
please any body tell, what going when following code at executing time?
SwingUtilities.invokeLater(new Runnable() {
public void run(){
new SwingDemo();
Thanks SIR....
invokeLater() places an object on the Swing Event Queue. Once all current events on the queue are processed, the run() method of the object will be called, on the event processing thread.
It is used to ensure that all UI updates are concurrency-safe. So situations such as a component's colour changing while it is being painted do not occur.
You essentially use invokeLater() whenever you need to update the UI and your code is not being run directly in response to a UI event (i.e. it's not inside or called directly by an actionPerformed(), mousePressed() etc method). Typically, this means your program has started some thread in the background and that background thread needs to update the UI. Subtly, it also means at the very beginning of your progam before you've started up your UI.
Some articles I've written that may help you:
- Threading with Swing
- SwingUtilities.invokeLater() - further explanation and example
edit: spam advertising removed