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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java: Disable the X close button

  • 05-01-2006 3:48pm
    #1
    Registered Users, Registered Users 2 Posts: 7,501 ✭✭✭


    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, Registered Users 2 Posts: 885 ✭✭✭clearz


    You could use a JDialog instead of a JFrame


  • Registered Users, Registered Users 2 Posts: 7,501 ✭✭✭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