How to disable (or hide) the close (x) button on a JFrame?

前端 未结 6 914
别跟我提以往
别跟我提以往 2020-12-09 08:47

I have a window (derived from JFrame) and I want to disable the close button during certain operations which are not interruptible. I know I can make the button not do anyt

相关标签:
6条回答
  • 2020-12-09 09:10

    To simply make them disappear, try the following:

    setUndecorated(true);
    
    0 讨论(0)
  • 2020-12-09 09:15

    This will help you:

    frame.setDefaultCloseOperation(0);
    
    0 讨论(0)
  • 2020-12-09 09:25

    For those coming to this later than 2008, there has been a change making it possible to do this. See this link

    Second response from the bottom shows how to do it by name.

    0 讨论(0)
  • 2020-12-09 09:27

    If I understand it correctly, this bug report indicates that this is currently not possible.

    0 讨论(0)
  • 2020-12-09 09:31

    Please try this

    frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
                try {
                    wait();
                } catch (InterruptedException ex) {
                    Logger.getLogger(WindowsActions.class.getName()).log(Level.SEVERE, null, ex);
                }
          }
        });
    
    0 讨论(0)
  • 2020-12-09 09:33

    This is probably the best you are going to get:

    setUndecorated(true);
    getRootPane().setWindowDecorationStyle(JRootPane.NONE);
    

    This will remove the entire titlebar, java doesn't really specify a way to remove individual components of the titlebar

    edit:

    There may be a way, check out these threads:

    • link 1
    • link 2
    0 讨论(0)
提交回复
热议问题