6

I would like to know if it is possible to create a JFrame window which has no default maximize/minimize(-) and close(x) buttons! I have added custom buttons on each frame so that the user does not have to mess around with the default ones on the top right corner of the window!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Kenzo
  • 1,767
  • 8
  • 30
  • 53

5 Answers5

5

You can use JWindow because is by default un_decorated, but you can setUndecorated() for JFrame/JDialog

another ways are

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • How do you do that with setUndecorated() fro JFrame/JDialog! Can you give an example ? – Kenzo Feb 01 '12 at 18:52
  • 1
    `setDefaultCloseOperations()` won't hide the buttons, it just changes the behaviour of the application when the window is closed. – millimoose Feb 01 '12 at 18:54
  • 1
    hmmm I posted link to API, then there isn't required any adds example – mKorbel Feb 01 '12 at 18:55
  • 1
    @Xris It's a method that takes one boolean parameter, there's not exactly a lot ways to use it. – millimoose Feb 01 '12 at 18:55
  • Also, `setUndecorated()` will make the entire window title bar and border disappear. This means you'll have to reimplement window moving and resizing as well. – millimoose Feb 01 '12 at 18:56
  • @Inerdial that could be little bit complicated, by default is better use un_decorated JFrame (can be used parent) as JDialog/JWindow, in the case that you required second/another popup window then JWindow is best at all – mKorbel Feb 01 '12 at 19:04
  • 1
    @mKorbel Any undecorated window, will require a custom implementation of the entire title bar. Doesn't matter whether a `JWindow` or a `JFrame` with the flag set to true. (A `JFrame` would indeed be better as the root window because of `EXIT_ON_CLOSE`.) – millimoose Feb 01 '12 at 19:09
  • @Inerdial agreed witout any comment(s) – mKorbel Feb 01 '12 at 19:15
5

Use JFrame.setDefaultLookAndFeelDecorated. It may not be the exact thing you need but doc says,

Provides a hint as to whether or not newly created JFrames should have their Window decorations (such as borders, widgets to close the window, title...) provided by the current look and feel.

Try this code:

JFrame frame = new JFrame("Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(100, 100);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
frame.setVisible(true);

This will remove the entire titlebar. Also take a look at this thread.

Otherwise use JWindows.

Vokail
  • 630
  • 8
  • 27
RanRag
  • 48,359
  • 38
  • 114
  • 167
  • The title bar on the window is totally gone so the side effect is user can't move the window by dragging on the title bar or resize the window. – Tony May 09 '16 at 19:13
0
JFrame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);

Will make the 'X' button no functioning. It's works for me.

chinna_82
  • 6,353
  • 17
  • 79
  • 134
0

If you are using Netbean then just unselect the resizable option in properties. It will only disable Minimize/Maximize Button.

0
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
Ryan Gek
  • 9
  • 3
  • A little bit of commentary around the code would be nice, but good answer to the question. – Michael Shopsin May 11 '16 at 14:39
  • Setting window decoration style seems unnecessarily. See docs: public void setWindowDecorationStyle(int windowDecorationStyle) Sets the type of Window decorations (such as borders, widgets for closing a Window, title ...) the JRootPane should provide. The default is to provide no Window decorations (NONE). – Gee Bee Mar 08 '18 at 14:59