• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doent wait for JTable to close.  RSS feed

 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If the user selects yes then the dynamic jTable appears and then its supposed to wait until the user closes/finishes the table before it carries on executing, but it doesn't wait it just continues to execute the next else if leaving the displayed table in the background. Any ideas on how i could fix this problem?



Thanks alot.
 
Rob Spoor
Sheriff
Posts: 21094
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does displayDynamicJTableScreen do? Does it show a modal dialog?
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Its a dynamically generated JTable that the user can edit the data, it also has three buttons - close, finish, delete all with the relevant action listeners eg:

Although it displays the table without problems doesn't wait for any editing/input/close/finish/delete it just carries on with execution. All the action listeners work, if i press a button it will do the relevant task - close, finish or delete there is also no problem with the editing. It just doesn't wait for anything immediately carries on with execution.

Any ideas??
Thanks
 
Rob Spoor
Sheriff
Posts: 21094
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see "frame" - does that mean it's a JFrame? If so, switch to using a modal JDialog.
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its a JInternalFrame, The problem is that a lot of other methods are also using displayDynamicJTableScreen(args[]) and there is no problem, it works perfectly it only seems to be giving this problem in this specific class where it executes all the else if() in the passed array(specified in xml). Could you please explain why changing it to a modal JDialog would help?

Thanks alot.
 
Rob Spoor
Sheriff
Posts: 21094
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A call to setVisible(true) of a modal JDialog is blocking; the method returns when the JDialog is closed / disposed / hidden.
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, i understand the concept now,(JFrame vs Dialog) l have asked and am not allowed to change it to a model dialog. I have tried wait() and notify() but i cant seem to get them to work. Any suggestions/ideas on how to fix this??

Thanks alot
 
Rob Spoor
Sheriff
Posts: 21094
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a CountDownLatch or Semaphore (since Java 5.0) could very well do the trick:
The first piece of code will block until countDown() is called at least once on the CountDownLatch. Since that only occurs when closing the internal frame, you know at that time that the frame has been closed. Just remember to also call countDown() in other button listeners, and also add an InternalFrameListener to the frame that calls countDown() in the internalFrameClosed method.
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton Its all good now.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!