Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to catch the close window event in a NetBeans Form ?  RSS feed

 
Sergio Marcello
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,
I'm using NetBeans IDE to develop a java desktop application.

This application makes use of threads. It starts with a JDialog and then the control goes to a Form which extends from FrameView.

When I close this Form within the menu "File/Exit", everything works fine, the applications shuts down, as well all the threads.

But when I close it using the windows close button - the X button that each window has at the top right edge - the form closes indeed, but the application is still "running" - I suppose that the threads are still alive in some way.

So the question: how can I capture the closing FrameView event ? I've used this code:

which obviously works fine in a JDialog, but it is not fired when I close the (window Form) FrameView.

More, from the IDE Members view in design mode, if i right click on a JDialog, the pop-up menu has an item, "events", from within I can choose Window events like, for example, WindowClosed. This option does not appears in a FrameView, and the only event available is "PropertyChange".

Any help would be greatly appreciated.

Regards,
Sergio.
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the setDefaultCloseOperation method. By default, it only disposes the frame. That should still close the application if that is the last active window / tray icon, and there are no other non-daemon threads.

Moving to Swing.
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Closing an Application provides some background information for you.

Rob Prime wrote:Check out the setDefaultCloseOperation method. By default, it only disposes the frame.


Actually the default is "hide". Change it to "dispose" and it should work as described.
 
Sergio Marcello
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob and Rob for the kind replies.

I'll try your suggestions as soon as I can and let you know my progress.

Regards,
Sergio.
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Change it to "dispose" and it should work as described.

I thought so. That also explains why it doesn't close, as I was sure I was right about the auto shutting down.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!