Skip to main content

Multiple JDialog windows causing unresponsiveness

1 reply [Last post]
Joined: 2008-10-16

Hi everyone,

I'm developing a program that has a main GUI window (JFrame) and multiple smaller JDialog windows.
I started noticing a great deal of unresponsiveness in my program, and I think it has something to do with the way I've been using threads. Only after writing my prog. and seeing the problems have I started reading about multi-threading and swing but some articles are confusing or contradicting... so essentially, my question is: what am I doing wrong.
Here's somewhat detailed description of my program:

1. The main GUI window displays a "live" animation of a landscape with moving objects within it.
2. The JDialog windows display looped playback of certain areas in the main GUI window.
3. The main GUI has various "small window managers", each manager holds references to a group of small windows and can pass them messages from the main GUI, and also make them visible/invisible so the user an page through more small windows than the screen can fit. Every manager implements the Runnable interface and I call Thread thread = new Thread(this).start( ) in the manager's constructor.
3. I have a server dedicated to sending new frames to the main GUI for the "live" image. The same server can also be queried for the smaller frames of the small windows - it has a built-in buffer where it stores old frames so that the small JDialog windows can get past frames of a certain region which are then sotred by the each small window and displayed in order.
4. One can also interact with each small JDialog window by clicking it with the mouse (I'm using the mouseClicked event) and then pressing a key to change that window's properties or even tell the main GUI window something about the region that the selected small window represents.
5. All together, everything is working. I put the main GUI window on the main( ) thread, where it loops through and updates its own frames to display the live picture - that same loop also interacts with the server to decide when to create new small windows.
6. Each small window works on its own thread. Each small window class implements the Runnable interface and I call Thread thread = new Thread(this).start( ) in the small window's constructor. (Should I use a worker thread instead? and if so, where should I invoke it later from? In the main GUI or within the small window's constructor?)
7. Each small window is its own ActionListener/MouseListener and knows to change properties or talk to its manager when the event needs to be passed on.

Thank you.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-02-27

What does your main GUI loop look like? Maybe there's a confusion between your main loop and the AWT Event Dispatch Thread (EDT).

Any time you modify a UI component the best practice would be to do so only on the EDT. If another thread is modifying things there can be weird performance issues. Check out:
That may help the mouse click behavior, maybe. Mouse events (and other events) are on the EDT and so if there's significant processing time in the method the GUI will appear unresponsive.

Otherwise, there's the potential that your other threads are hogging the CPU and starving the EDT.

When do you notice the unresponsive behavior the most?