Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove just the Maximize button from a JFrame?

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.

like image 710
Mahdi_Nine Avatar asked Apr 11 '11 18:04

Mahdi_Nine


People also ask

How do I fix the maximization error in 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.

Is there a jframewithout minimize/maximize buttons?

This is not a JFramewithout minimize/maximize buttons. It’s just a regular JDialog. – Martin Sep 15 '16 at 14:55 Add a comment |

How do I change the size of a JFrame in Java?

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.

How do I remove the maximize button from a window?

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.


2 Answers

Make it not resizable:

frame.setResizable(false); 

You will still have the minimize and close buttons.

like image 141
sjr Avatar answered Sep 30 '22 20:09

sjr


You can't remove the button from a JFrame. Use a JDialog instead. It doesn't have a maximize button.

like image 31
jzd Avatar answered Sep 30 '22 19:09

jzd