Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default 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:
    Java Code:
            javax.swing.JFrame jf = app.getMainFrame();
            jf.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
    and it had no effect. This should be a no brainer but I simply can not figure this out. Can someone please help?

  2. #2
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    Perhaps you are setting the default close operation on the wrong frame? It's hard to tell without seeing your entire program.

  3. #3
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    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);
    .
    .
    .

  4. #4
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    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.

  5. #5
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    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.

  6. #6
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    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.

  7. #7
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    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?

  8. #8
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    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();
    ...

  9. #9
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    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.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    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

  11. #11
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    Quote Originally Posted by madroadbiker View Post
    Actually just this one line:

    javax.swing.JFrame jf = app.getMainFrame();

    causes the problem. Well, problem solved but I don't understand why.
    I don't know either. That line looks harmless enough. I use eclipse for most of my UI work.

  12. #12
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    Well thanks for your help. I'm going to consider this solved

Similar Threads

  1. Replies: 0
    Last Post: 06-07-2010, 07:23 PM
  2. Adding "Choose File" button to applet
    By mju4t in forum Java Applets
    Replies: 1
    Last Post: 09-17-2009, 09:11 AM
  3. Replies: 2
    Last Post: 01-29-2009, 08:17 PM
  4. Replies: 10
    Last Post: 12-30-2008, 04:46 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •