How can I remove the close button of a JFrame in Swing while the min/max buttons and the rest of the frame decoration shall still be available? TYVMIA
Asked
Active
Viewed 54 times
1
-
2In Java/Swing - you can't ... or not from a "natively generated" window decoration. You "could" make a look and feel delegate which did the same job, but you quickly lose cross platform conformance. You could also "roll your own" by making the window undecorated and apply your own "fake" window decoration, but it's much in the same as crafting your own look and feel delegate - some problems and issues – MadProgrammer Apr 29 '23 at 01:34
-
Is cross-platform compatibility necessary for your project? – Cardinal System Apr 29 '23 at 01:48
-
Cross-platform compatibility is important, yes. – Natasha Apr 29 '23 at 01:51
-
@MadProgrammer Would you mind copying your above comment as an answer to get the well earned reputation points? – Natasha Apr 29 '23 at 02:27
-
1(BTW you can set Swing to ignore that button: [`setDefaultCloseOperation()`](https://docs.oracle.com/en/java/javase/20/docs/api/java.desktop/javax/swing/JFrame.html#setDefaultCloseOperation(int))) – user16320675 Apr 29 '23 at 05:45
1 Answers
1
In Java/Swing - you can't ... or not from a "natively generated" window decoration.
You "could" make a look and feel delegate which did the same job, but you quickly lose cross platform conformance.
You could also "roll your own" by making the window undecorated and apply your own "fake" window decoration, but it's much in the same as crafting your own look and feel delegate - same problems and issues
Take a look at Customizing the Title bar of an Application Window for some "inspiration".
This also suggestions making use of JNI/JNA, which further complicates the issues.
You might also like to have a look at this example, it demonstrates how you can move an undecorated window, resizing is simular, but a adds and additional level of complexity.

MadProgrammer
- 343,457
- 22
- 230
- 366