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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:23:12+00:00 2026-05-12T23:23:12+00:00

I would like to disable the close x in the upper left corner of

  • 0

I would like to disable the close x in the upper left corner of my JOptionPane how would I do this?

  • 1 1 Answer
  • 1 View
  • 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-12T23:23:12+00:00Added an answer on May 12, 2026 at 11:23 pm

    You could always just show the dialog again when the user tries to close it without selecting an option. There’s an example of how to override the default closing behavior at sun.com. Look under “Stopping Automatic Dialog Closing” and they have the following code:

    final JOptionPane optionPane = new JOptionPane(
                    "The only way to close this dialog is by\n"
                    + "pressing one of the following buttons.\n"
                    + "Do you understand?",
                    JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.YES_NO_OPTION);
    
    final JDialog dialog = new JDialog(frame, 
                                 "Click a button",
                                 true);
    dialog.setContentPane(optionPane);
    dialog.setDefaultCloseOperation(
        JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            setLabel("Thwarted user attempt to close window.");
        }
    });
    
    optionPane.addPropertyChangeListener(
        new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();
    
                if (dialog.isVisible() 
                 && (e.getSource() == optionPane)
                 && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                    //If you were going to check something
                    //before closing the window, you'd do
                    //it here.
                    dialog.setVisible(false);
                }
            }
        });
    dialog.pack();
    dialog.setVisible(true);
    
    int value = ((Integer)optionPane.getValue()).intValue();
    if (value == JOptionPane.YES_OPTION) {
        setLabel("Good.");
    } else if (value == JOptionPane.NO_OPTION) {
        setLabel("Try using the window decorations "
                 + "to close the non-auto-closing dialog. "
                 + "You can't!");
    }
    

    Using that code, you could easily adapt the commented section to only allow the window to be closed when the user has clicked one of the available options and not the close button.

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

Sidebar

Related Questions

I have a button that I would like to disable when the form submits
I would like to enable/disable some code based on a custom solution configuration I
I would like to know if there is a way to disable automatic loading
I have a div which is creating through ajax, i would like to disable
I would like to disable the context menu that appears after a long tap
Using jQuery, I would like to disable scrolling of the body: My idea is
I have an iframe that loads a page that I would like to disable
I have an iframe that loads a page that I would like to disable
When I press a button, I would like to disable screen rotation on all
I would like to disable the same origin policy on XMLHttpRequests in my own

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.