Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 anything (or call a handler in a WindowListener) by calling

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 

but I would like to make it clear visually that it is pointless to click it.

like image 942
florin Avatar asked Nov 09 '08 18:11

florin


People also ask

How do you remove minimize maximize close button from JFrame?

Try this code: JFrame frame = new JFrame("Example"); frame. setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame.

How do I remove the Close button from a Jpanel?

You can't remove close Button from JFrames, but you can disable by calling setDefaultCloseOperation(WindowConstants. DO_NOTHING_ON_CLOSE) on that JFrame.

How do I close a JFrame without closing another?

You can use setVisible(false) on your JFrame if you want to display the same frame again. Otherwise call dispose() to remove all of the native screen resources.

How do you make a JFrame close when a button is pressed?

You can use super. dispose() method which is more similar to close operation. Show activity on this post. You cat use setVisible () method of JFrame (and set visibility to false ) or dispose () method which is more similar to close operation.


1 Answers

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
like image 185
Malfist Avatar answered Sep 29 '22 11:09

Malfist