• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dead lock in GUI?

 
Attila J�borszki
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a bad feeling that dead lock can occur in my client GUI. I realized that sometimes my app gets frozen when displaying its main window (JFrame). I was able to trek the problem till a setEnabled method is called on a JButton. My app gets frozen at this point. I use a lot of ActionListener and PropertyChangeListener ...

I realized that if I put a Thread.sleep(40) between displaying my main window and filling it up with default values ... this frozen does not occur.

So, should I prepare my GUI with considering some kind of concurrency in Swing components? Should I lock my buttons, textFields ... before I use it?

Thanks,
Attila
[ December 06, 2008: Message edited by: Attila J�borszki ]
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw you have another question about your application freezing because of a textfield. Are you sure it's not from the same problem?

Anyway, we can't really help you because we don't know the exact code which is involved.

You could also try to:
- set the default values before showing the main window.
- always use SwingUtilities.invokeLater() for stuff that changes the look of the application (if it's performed from a thread which is not the event dispatcher one)
 
Attila J�borszki
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alecsandru Cocarla:
I saw you have another question about your application freezing because of a textfield. Are you sure it's not from the same problem?


It is the same problem ... At first time, I found this insertString issue but later I realized that the ActionListener belongs to this textField is called when the insertString is executed, this ActionListener updates the Model belongs to this View, but the Model warns the View that the content of its variable changed ... the View executes a check if the start button can be enabled because of this change ... so I finally got to this setEnabled method ... and I got stuck here ...
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you're mentioning some kind of "default values" (or state) of the main window, I'd say your problem might be caused by trying to change the window's looks from a thread which is different from the event dispatcher thread.
Did you try to initialize all this stuff as I told you (either before showing the window, or using SwingUtilities.invokeLater())?
 
Attila J�borszki
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SwingUtilities.invokeLater() works! I put the initDefault methods into it and it works.

I used a SUN example how to implement MVC. In this example, these initDefault methods are called after the GUI is assembled and before it is set visible. But in my implementation this does not work ... I have to call these methods after the GUI is set visible.

Thanks for the help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic