quickie question

Hi, I'm not really a Swing expert so my question may be a little naive, but here it goes.

I'm creating a plugin that implements ProjectComponent
in my projectOpened method before I do a bunch of analytical initialization junk i would like to present for the duration of this work a little message window saying it is doing something. I tried creating a frame with a panel and JLabel message in it, called the pack and show method, then called a method which does a lot of processing, when that is done, call the dispose method on the frame.
sorta like this

Tester tester = new Tester();
tester.pack();
tester.show();
initToolWindow();
tester.dispose();

It sort of works, the window pops up and closes at the right time, but the JLabel is not displayed. If i remove the dispose method, the label shows up after all my processing is done.

thanks,
-Andre

2 comments
Comment actions Permalink

The problem is that you are doing all of those things in the same thread.

All GUI updates occur in the AWT thread. If you are inside a callback method (e.g. actionPerformed), your code is already running inside the AWT thread.

I don't know what the current thread that your code is running from, because I haven't tried what you are doing.

But in general, if you want to make a GUI change, you should wrap it in:


If you need to perform a lengthy operation, you should create a new Thread for that, and then within that thread you can make calls to SwingUtilities.invokeLater() to update the GUI.

The invokeLater() places your code in the queue to be executed in the AWT-Thread.

It is important to know if you are already in the AWT-Thread, because then it is very important to return as soon as possible because the those GUI updates won't happen until you return control.


IDEA may have additional requirements. The above is just standard SWING programming..

-Alex

0
Comment actions Permalink

Ahh cool thank you for the insight, I had a feeling it was something along those lines. I tried out doing it the way you prescribed, and i got some errors from idea, but it worked in a test done outside of IDEA, see below.

In one of the errors it mentioned using application.runReadAction(work) which must run in the same AWT thread, because it blocked again.

0

Please sign in to leave a comment.