Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:43:37+00:00 2026-05-27T11:43:37+00:00

I have a pretty standard Java Desktop Application in NetBeans. I recently added a

  • 0

I have a pretty standard Java Desktop Application in NetBeans. I recently added a jDialog modal as a welcome banner and started having an issue closing the application. If I use the default menu (File > Exit) on the main frame it seems to always close correctly. If I hit the close button on the main window the frame will disappear but the JVM will still be running.

Removing the call to show the dialog box completely fixes the problem, so I am guessing that’s where the problem lies. I’m pretty sure the dialog is properly being disposed, as that was my first guess as two why the JVM wouldn’t exit.

To check my sanity, instead of calling the my welcome dialog I started calling the default showAboutBox() that is automatically generated by NetBeans when the application was created. Same issue. The dialog works fine when called through the menu (I’m not sure if that’s because it’s an Action or not) but will cause the JVM not to exit correctly if called directly.

Both dialogs have the setDefaultCloseOperation() set to DISPOSE_ON_CLOSE.

Below is the code snippet for calling the aboutBox (which is the same as my welcome dialog):

@Action
public void showAboutBox() {
    if (aboutBox == null) {
        JFrame mainFrame = MyApp.getApplication().getMainFrame();
        aboutBox = new MyAboutBox(mainFrame);
        aboutBox.setLocationRelativeTo(mainFrame);
    }
    MyApp.getApplication().show(aboutBox);
}

Anyways, I solved the issue myself.

So I guess you can’t call a dialog in the constructor…

The fix…

/*
 * MyApp.java
 */

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class MyApp extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        show(new MyView(this));
        MyView.doThisCodeAfterTheMainFrameIsLoaded();
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of MyApp
     */
    public static MyApp getApplication() {
        return Application.getInstance(MyApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(MyApp.class, args);
    }

}




/*
 * MyView.java
 */

/**
 * The application's main frame.
 */
public class MyView extends FrameView {

    public MyView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // Don't call a dialog here!
        // showAboutBox();

    }

    public static void doThisCodeAfterTheMainFrameIsLoaded() {

        JFrame mainFrame = MyApp.getApplication().getMainFrame();
        JDialog welcome = new MyWelcome(mainFrame);
        welcome.setLocationRelativeTo(mainFrame);

        MyApp.getApplication().show(welcome);

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:43:38+00:00Added an answer on May 27, 2026 at 11:43 am

    Add the following:

    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    

    See the JFrame documentation:

    Unlike a Frame, a JFrame has some notion of how to respond when the
    user attempts to close the window. The default behavior is to simply
    hide the JFrame when the user closes the window. To change the default
    behavior, you invoke the method setDefaultCloseOperation(int). To make
    the JFrame behave the same as a Frame instance, use
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE).

    and then look at JFrame.setDefaultCloseOperation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty standard table set-up in a current application using the .NET
I am currently writing an financial application, and we have a pretty standard customer
I have a pretty standard django app, and am wondering how to set the
I have a pretty standard database sitting on SQL Server. To manage the data
I have a pretty standard Repository pattern going, where repositories are injected into my
I have what I imagine to be a pretty standard web-interface. There are 4
I have pretty much finished my first working Symbian application, but in my hastened
I have a pretty standard contact form that uses a cfc for processing now.
I'm pretty new to Android development, but I have some experience with Java and
I have recently learnt how to program in java, I was looking at some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.