Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java: Disable the X close button

Options
  • 05-01-2006 4:48pm
    #1
    Registered Users Posts: 7,500 ✭✭✭


    How can i disable the X close button in my JFrame.

    I want my users to exit using a button supplied. Or if it is possible call a piece of code when the user hits the X button.

    I would rather use Disable the X button.

    I know i can use
    this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    

    But this does not fade the button


Comments

  • Closed Accounts Posts: 603 ✭✭✭shamrock2004


    Hi. I am only familiar with frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); But i guess if you omit this, then it will not close when you click the x button. Why do you wish to do this anyway?
    regards
    Shamrock?


  • Closed Accounts Posts: 324 ✭✭madramor


    Or if it is possible call a piece of code when the user hits the X button.

    heres how to perform code when user click X to close.
    this does a standard do you want to close dialog.
    final JFrame f = new MyFrame();
    f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    f.addWindowListener(new WindowAdapter(){
       public void windowClosing(WindowEvent e){
          int n = JOptionPane.showConfirmDialog(f,"Do you want to close Application?","Close Application",JOptionPane.YES_NO_OPTION);
          if(n == 0){
             LogOffRequest.doIt(back[1]);
             System.exit(0);
          }
       }
    });
    


  • Registered Users Posts: 877 ✭✭✭clearz


    You could use a JDialog instead of a JFrame


  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    madramor wrote:
    heres how to perform code when user click X to close.
    this does a standard do you want to close dialog.
    final JFrame f = new MyFrame();
    f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    f.addWindowListener(new WindowAdapter(){
       public void windowClosing(WindowEvent e){
          int n = JOptionPane.showConfirmDialog(f,"Do you want to close Application?","Close Application",JOptionPane.YES_NO_OPTION);
          if(n == 0){
             LogOffRequest.doIt(back[1]);
             System.exit(0);
          }
       }
    });
    


    worked very well thankyou.


Advertisement