Process won't close after adding mouse listener

I want to know what the issue is when I try to close my Java Swing application when I add a listener to the form frameview. Here's how to produce my problem: In Netbeans, create a new Swing application project, then in the main class, create a local method that adds an empty mouse listener to the main window via this.getMainFrame().addMouseListener(new MouseAdapter(){}). Go into the form class, and call that method using .getApplication().createListenerMethod() in the form's constructor, right after InitComponents().

Run the program and you'll see that after closing it, netbean's little progress bar says it's still running :(

I find that if I set the form's default close operation to "dispose", it solves the problem. Why does it do this if I call a method from the form to the main application class to add a listener to itself? The reason why I'm adding it like this is that I want to keep the main application logic in the main file class, I feel uneasy writing code a in form designer parsed class.

Answers


I don't think that the mouse listener has anything to do with what you see, though it's possible that the NB code-generation wizard does some weird stuff in the protected regions.

Swing does not auto-dispose the frames/windows in case you want to reuse them (show/hide multiple times). Usually you want to keep track of closed windows/dispose them from a window listener or in simpler cases, use JFrame.setDefaultCloseOperation(). Most often each reasonably big Swing application has some sort of global state-tracking facility that disposes all windows and shuts down thread pools when the termination condition is met.

You can use NetBeans RCP as well that takes care of many aspects of a GUI application if you are willing to invest the time to learn it (I would not recommend for small apps). Another alternatives for Swing app frameworks are are Jide Software's JDAF (my preferred) and "Better Swing Application Framework" (from kenai.com)


Need Your Help

gulp-ruby-sass can't find mixins

sass mixins gulp

I'm just getting started with Gulp.js and Sass and I'm stuck with using mixins.

Android - Crash after click push notification message

android cordova google-cloud-messaging

I'm using cordova for my project. My app crash after I click push notification message. I got this error message in my log cat.