Jbutton action, setIcon is being executed at the end of action?

The ActionListener is invoked on the AWT event dispatch thread. The same thread also processes any other events like paints. Thus, as long as your actionPerformed() method not returns, nothing is painted (or anything else on the GUI is changed) You should do longer-running actions outside of this thread (i.e.

Start a new Thread doing this), and then for GUI changes later call back with EventQueue. InvokeLater (or EventQueue. InvokeAndWait ).

The ActionListener is invoked on the AWT event dispatch thread. The same thread also processes any other events like paints. Thus, as long as your actionPerformed() method not returns, nothing is painted (or anything else on the GUI is changed).

You should do longer-running actions outside of this thread (i.e. Start a new Thread doing this), and then for GUI changes later call back with EventQueue. InvokeLater (or EventQueue.

InvokeAndWait).

I was turning around in a one single class, I will use another one to call the main class and then I will try wait & notify methods. I must learn more about EventQueue. By the way, thank you very much PaÅ­lo Ebermann for your quick reply.

– piratejackus Feb 12 at 1:58 I found a quick fix for this icon refresh thing "update(getGraphics());", it works fine for me, maybe it helps to others too. – piratejackus Feb 12 at 2:32 No, that's not a good solution. Better to fallow Paulo's and Uhlen's recommendations (1+ to each) – Hovercraft Full Of Eels Feb 12 at 3:12 @PaÅ­lo Ebermann – piratejackus Feb 13 at 21:24 @PaÅ­lo Ebermann when I use SwingUtilities.

InvokeAndWait the code goes in debug mode showing class EventDispatchThread.run() line:172. And it locks. The program is still running.It comes in the second execution of the same code.

So I put if (SwingUtilities. IsEventDispatchThread( )) before concerning code and it enters this case in the second times of execution. Does it mean that the main thread is still running or my subthread is running?

I couldn't clearly understand from linkdownload.oracle. Com/javase/tutorial/uiswing/concurrency/… – piratejackus Feb 13 at 21:31.

PaÅ­lo Ebermann gives the correct answer but I just wanna add that never sleep on the Event Dispatch Thread! That only makes things worse. Swing is powerful toolkit, but it's tolerance to incorrect threading (sleep on EDT, update UI outside EDT) is IMHO number one reason why people have trouble with Swing.

If it instead would fail with RuntimeException under such circumstances a lot of bugs would be exposed and thus more easily fixed.

Thanks Uhlen, I will keep that in mind. – piratejackus Feb 12 at 2:06.

I must learn more about EventQueue. Read the section from the Swing tutorial on Concurrency. Maybe your Thread.

Sleep(...) code should be replaced with a Swing Timer. The Swing tutorial also has a section on "How to Use Swing Timers".

So here after I set icon of the jbutton, I want to see it before disposing the old jframe and launching the new one (next level in the game). Try { Thread. Actually last one seems to be working but eclipse jumps to debug mode without any exception and it doesn't kill the process even I close the frame.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions