A Par
A Par

Reputation: 17

Remove close (X) button from the top right corner and keep min/max on JFrame

I want to create my UI with a JFrame and a minimize and maximize look-alike button with the same functionality as normal minimize and maximize buttons but I am not sure how. I want to take this approach so there will not be an X button in the top corner.

Upvotes: 0

Views: 2574

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122414

For an undecorated frame you'd have to use JWindow instead of JFrame, then render your own title bar.

Of course, whatever you render will only look right on one particular platform in one particular look and feel (unless you write your own logic to handle different platform conventions by hand). For example, Mac users will expect the close, min and max buttons to be traffic light coloured circles at the left hand end of the title bar, not square buttons at the right.

Upvotes: 1

Maroun
Maroun

Reputation: 96016

You cannot remove it and keep the other two, however, you can disable it using setDefaultCloseOperation:

setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) 

Note that this will not make the button unclickable but will disable the functionality.

Upvotes: 1

Related Questions