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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:09:38+00:00 2026-06-10T13:09:38+00:00

I am making a word processor application in order to practise Java and I

  • 0

I am making a word processor application in order to practise Java and I would like it so that when the user attempts to close the appliction, a JFrame will come up asking to save changes.

I was thinking about setDefaultCloseOperation() but I have had little luck so far. I would also like it to appear whent he user clicks the “X” on the top right of the window aswell if possible.

  • 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-10T13:09:39+00:00Added an answer on June 10, 2026 at 1:09 pm

    You can set the JFrame DefaultCloseOperation to something like DO_NOTHING, and then, set a WindowsListener to grab the close event and do what you want. I’ll post an exemple in a few minutes .

    EDIT: Here’s the example :

    public static void main(String[] args) {
            final JFrame frame = new JFrame("Test Frame");
    
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    
            frame.setSize(800, 600);
    
            frame.addWindowListener(new WindowAdapter() {
                //I skipped unused callbacks for readability
    
                @Override
                public void windowClosing(WindowEvent e) {
                    if(JOptionPane.showConfirmDialog(frame, "Are you sure ?") == JOptionPane.OK_OPTION){
                        frame.setVisible(false);
                        frame.dispose();
                    }
                }
            });
    
            frame.setVisible(true);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I implement a word processor on a website I'm making? The point
I'm making a website that (essentially) lets the user submit a word, matches it
I'm making an application that will change position of two characters in Word. Imports
Making a simple application, so when the user logs out of Windows, it of
I'm making this word game and when you submit a word I want that
I'm making a command-line word editor program. The user is prompted to input a
I'm currently making a word game for iOS that, when loading, reads in a
Making a specific word entered into a textbox trigger a password prompt that when
I am making an app a bit like a dictionary, where a user clicks
I have problem in making silverlight application, I need to create a Word Document

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.