I have a JFrame and want to remove the maximize button from that.
I wrote the code below, but it removed maximize, minimize, and close from my JFrame
.
JFrame frame = new JFrame(); frame.add(kart); frame.setUndecorated(true); frame.setVisible(true); frame.setSize(400, 400);
I want to only remove the maximize button from the JFrame
.
The simplest and yet effective solution is to replace JFrame with JDialog as the latter does not have a maximize button. Other feasible “Java-based” solution is remove the title bar and painstakingly implement customized title bar. The solution here neutralizes the effect of maximization and flashing a error message.
This is not a JFramewithout minimize/maximize buttons. It’s just a regular JDialog. – Martin Sep 15 '16 at 14:55 Add a comment |
After setting the size of a JFrame we can still change the size by putting the cursor at the corners and dragging it or if we press resize option next to close at the top right corner, it will maximize to the size of a full screen. This happens because resize is set to true by default for JFrame class.
Using setResizable (false) will remove the maximize button only, at the cost of not being able to resize the window. Lastly, as mentioned by trashgod, the setUndecorated (true) method will disable the frame decorations, removing the title bar and window edges.
Make it not resizable:
frame.setResizable(false);
You will still have the minimize and close buttons.
You can't remove the button from a JFrame
. Use a JDialog
instead. It doesn't have a maximize button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With