Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java: Disable the X close button

  • 05-01-2006 04:48PM
    #1
    Registered Users, Registered Users 2 Posts: 7,544 ✭✭✭


    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,544 ✭✭✭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