Results 1 to 12 of 12
- 03-21-2011, 02:07 PM #1
Default "X" button or EXIT_ON_CLOSE will not work
First of all, please know that I searched all the forums here and could not find any pertinent information. If I missed it somehow, I am sorry.
This is my second java gui program I've written using NetBeans 6.9.1. In both programs the main window gets created and comes up with the standard buttons you see on all gui windows including a usually red "X" button used to exit the program. In my first program, when I click that button, the programs exits as it is supposed to. In my second program when I click the "X" button, the window goes away, however java is still actually running and I have to quit it separately. I've compared the two programs over and over again and see no obvious difference in that area. I even tried something like this:
and it had no effect. This should be a no brainer but I simply can not figure this out. Can someone please help?Java Code:javax.swing.JFrame jf = app.getMainFrame(); jf.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
- 03-21-2011, 02:47 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
Perhaps you are setting the default close operation on the wrong frame? It's hard to tell without seeing your entire program.
- 03-21-2011, 03:17 PM #3
Ok here is a little more code to look at. The code up to and including the call to initComponents was automatically generated for me. The myInitializations call is mine. I pass 'app' to my initialize function where you see the other 2 lines I posted earlier. This is the main frame. Where else would I set the default close?
Java Code:/** * The application's main frame. */ public class TextFileAnalyzerView extends FrameView { public TextFileAnalyzerView(SingleFrameApplication app) { super(app); initComponents(); myInitializations(app); . . . private void myInitializations(SingleFrameApplication app) { javax.swing.JFrame jf = app.getMainFrame(); jf.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); . . .
- 03-21-2011, 03:30 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
I'm sorry, but I'm not familiar with FrameView. Is that from some 3rd party widget library? I'm guessing that FrameView is the real top-level container and that your SingleFrameApplication is just a child element of that. So even if you dispose of the SingleFrameApplication, FrameView is still alive and kicking.
Of course if your first program also used FrameView, then I'm way off. Sorry.
- 03-21-2011, 03:39 PM #5
To create the project, I clicked on "File New Project..." in netbeans. It popped up a menu with a list of selections. I chose "Java" under Categories and "java Desktop Application" under Projects. Here's what the description says for java Desktop Application:
Creates a skeleton of a desktop application based on the Swing Application Framework (JSR 296). This template provides basic application infrastructure such as a menu bar, persisting of window state, and status bar. With this template, you can also generate code to create a GUI interface for a database table.
It then created the code I posted including the FrameView stuff in both projects. This is why I can't figure out one works and the other doesn't.
- 03-21-2011, 03:51 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
Ok. I created a project in Netbeans (6.9.1) and ran it. I clicked the "X" and it closed properly (no hanging process). I didn't add any code; I just ran the skeleton app. I didn't even have to add the call to setDefaultCloseOperation(). It worked fine as is. So there is something else going on here, but I'm not sure what.
- 03-21-2011, 03:54 PM #7
I can't figure out what I did either. Maybe I should start stubbing out all my functions one at a time until it works again. Does that sound reasonable?
- 03-21-2011, 03:56 PM #8
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
I was able to recreate your problem (I think). Like I said before, it seemed unnecessary to add the setDefaultCloseOperation(). When added it, the process hung after I clicked "X". I commented it out (see below) and it once again worked fine. So my guess is that the setDefaultCloseOperation() is overriding some behavior. But I'm not a Swing expert, so I don't know. Try commenting out those two lines as I did here:
Java Code:/** * The application's main frame. */ public class TestFrameViewView extends FrameView { public TestFrameViewView(SingleFrameApplication app) { super(app); [B] //javax.swing.JFrame jf = app.getMainFrame(); //jf.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);[/B] initComponents(); ...
- 03-21-2011, 04:06 PM #9
That worked! I don't understand because I thought it didn't work in the first place and that's what prompted me to put those 2 lines in. Actually just this one line:
javax.swing.JFrame jf = app.getMainFrame();
causes the problem. Well, problem solved but I don't understand why.
- 03-21-2011, 04:11 PM #10
It should be understood that the NetBeans visual designer aka Matisse is not a beginner's tool, it's targeted at seasoned Swing developers who can use it to increase their productivity. For the rest of us, it's more of a pain than it's worth.
You need to master the intricacies of Swing coding first.
Just my 0.02.
db
- 03-21-2011, 04:26 PM #11
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
- 03-21-2011, 04:35 PM #12
Similar Threads
-
Is there a way to play the video until I click the "start "button?
By aprilcomingsoon in forum XMLReplies: 0Last Post: 06-07-2010, 06:23 PM -
Adding "Choose File" button to applet
By mju4t in forum Java AppletsReplies: 1Last Post: 09-17-2009, 08:11 AM -
Viewing XML using Default Browser - Java's "Desktop" API
By scotter59 in forum XMLReplies: 2Last Post: 01-29-2009, 07:17 PM -
pretty much completed hangman, but "new" button is not working
By diggitydoggz in forum New To JavaReplies: 10Last Post: 12-30-2008, 03:46 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks