Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the default minimize/maximize and close buttons on JFrame window in Java?

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!

like image 346
Xris Avatar asked Feb 01 '12 18:02

Xris


People also ask

How do you hide the minimize and maximize buttons?

Use the ResizeMode property By setting the ResizeMode property to CanMinimize only the Minimize button will be visible. The maximize button will be hidden and the resizing will be disabled. This is demonstrated in Example 2.

How do you make a JFrame not Minimizable?

Here is the code to disable maximize and close button: JFrame frame = new JFrame(); frame. setResizable(false); //Disable the Resize Button // Disable the Close button frame.

How do I hide a window in Java?

You need to use setVisible(false) on the instance of the window you've created earlier.

How do I close a JFrame without exiting?

You have to add the button and add an actionListener on the button. Then in the actionPerformed method of that action listener, call the . dispose() method on the frame you want to get rid of.


1 Answers

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

another ways are

  • implements WindowListener

  • setDefaultCloseOperations

like image 121
mKorbel Avatar answered Nov 15 '22 00:11

mKorbel