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 8193999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:40:22+00:00 2026-06-07T04:40:22+00:00

I started writing a small program to learn a bit more about java and

  • 0

I started writing a small program to learn a bit more about java and try to design my layouts by hand without always using NetBeans.

Thing is, when I run my project and close it, it won’t stop running in NetBeans, so everytime I re-run it creates another run. By searching and looking at another GUI I had created using NetBeans I thought adding the

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

would do the trick, but I guess I am wrong.

Can someone please explain me what I should do?

Here is a SSCCE of my programa: http://pastebin.com/QhKpwdDw

Thank you very much in advance!

  • 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-06-07T04:40:24+00:00Added an answer on June 7, 2026 at 4:40 am

    You might want to take a look at this question: How to close a Java Swing application from the code, as it deals with closing the application in general and also how to ensure it completely terminated.

    But to answer your question quickly, there are a couple of options.

    Option 1

    Since you are extending JFrame in your class, you can just use EXIT_ON_CLOSE to quit.

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    

    NOTE: EXIT_ON_CLOSE exits all JFrames in your application, not just the one it is applied to.

    Option 2

    This is most likely not the answer you want, but DISPOSE_ON_CLOSE will close only the JFrame you are applying it to.

    If you have multiple JFrames open, or if you have any other Threads, they will keep running and the program will not end. But if you only have one Thread and one JFrame, this will close the application.

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    

    My Preference

    I would go with Option 1, disagreeing with everyone else. It is directly tied to JFrame and not dependent on WindowConstants, which makes things cleaner and more reliable. But more importantly, it closes all of the windows, not just the one that you apply it to.

    Even though it looks like you only have one window, you may have other internal Threads elsewhere in your program that NetBeans is throwing in there.

    To be sure everything closes, you want to use EXIT_ON_CLOSE.

    Extra Information

    For a discussion on how DISPOSE_ON_CLOSE and EXIT_ON_CLOSE differ: http://www.coderanch.com/t/340183/GUI/java/DISPOSE-CLOSE-vs-EXIT-CLOSE

    Documentation on JFrame's EXIT_ON_CLOSE: http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JFrame.html#EXIT_ON_CLOSE

    Documentation on DISPOSE_ON_CLOSE and other WindowConstants: http://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/WindowConstants.html#DISPOSE_ON_CLOSE

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

Sidebar

Related Questions

Right now, I am trying to learn Scala . I've started small, writing some
I've just started writing GAE web applications in Java so I'm kind of new
Recently, I started writing a program to compare DNA sequence. As the alphabet only
I started writing a small wrapper class to take care of my excel operations:
So far I have been writing programs in Java. So when I started C++,
I have started learning Python by writing a small application using Python 3.1 and
I am writing some small program in C--some log in, log out, create account,
In order to get started with bindings, I'm writing a small application that converts
I downloaded Flash Builder from here : Download I recently started writing some small
I'm fairly new to C and have started out writing a small library with

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.