• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing - Parent window goes back on closing the model dialog  RSS feed

 
Senthamarai Prabhu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have application which will show the model dialog in the middle of the operation. In that, once I close the model dialog the main application is going back to other applications opened in my machine.

My Sample Code



Basically, I want the main application need to be disabled till the selected operation completes.
This is used work good in Java 1.5.0.4. Now I have above stated problem in JDK 1.6.0.10

Please help to resolve this issue.

Thanks in Advance.

S Prabhu
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried your code, and I have the same problem. The ABCDEF frame never is activated again.

The strange thing is, when I made the dialog non-modal, it still was acting as if it were modal; clicking on the frame didn't work at all, and the dialog's border flashed.

It looks like there is another invisible modal window, yet when I printed the active windows (using Window.getWindows()) there were only the frame and the dialog. I'm clueless...
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your culprit is

Why are you calling this before displaying the dialog? What do you think it does?

..and welcome to the Ranch
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, it's the setEnabled(false) call that is causing it to happen. You are disabling your main window. Just remove that line. There's no need for it. Also, you should be doing EXIT_ON_CLOSE instead of DISPOSE for your JFrame and when your exit button is pressed you should be doing System.exit(0), otherwise the VM will never end.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:Also, you should be doing EXIT_ON_CLOSE instead of DISPOSE for your JFrame and when your exit button is pressed you should be doing System.exit(0), otherwise the VM will never end.

Actually, if all windows have been closed and there are no more non-daemon threads, the JVM will close automatically.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Gregg Bolinger wrote:Also, you should be doing EXIT_ON_CLOSE instead of DISPOSE for your JFrame and when your exit button is pressed you should be doing System.exit(0), otherwise the VM will never end.

Actually, if all windows have been closed and there are no more non-daemon threads, the JVM will close automatically.


Hey, you're right. I'll recant a bit and just say it would be better if you did EXIT_ON_CLOSE and System.exit(0). I have no real logic as to why its better but from a code clarity perspective it makes more sense. It does take a bit longer for the vm to realize there are no more non-daemon threads and it should shutdown though.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Gregg.
Having EXIT_ON_CLOSE definitely lends more clarity.
I am personally inclined to have only one clearly marked exit point to the application, which, in most of the cases is the termination of the main frame.
 
Senthamarai Prabhu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for all your response on this topic.



Before showing the model dialog box in the action, I have to perform some operation which normally take long time.
In this time I don't want use to access the GUI. So, I am disabling the GUI.
Even after the model dialog I do some operation, which take long time again.
On the operation is completed, I will re-enable the GUI as show in the above code snippet.

How I make this disabled parent on top after disposing the model dialog?

Thanks
S Prabhu
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do know that the Event Dispatcher Thread will block while you are executing those lengthy pieces of code? In other words, the disabling / enabling will problably not even be visible.
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!