How to make a window smaller than 125 x 50 in Java?

I am trying to create a 50x50 window in Java, but the window will not be smaller than 125x50, even if I try to manually resize it.

Here is my code:

import javax.swing.*;
public class smallwindow {
    public static void main(String args[]) {
        JFrame frame = new JFrame("");
        frame.setSize(50, 50);
        frame.setVisible(true);
    }
}

I am running this with the latest version of Java on Mac OS X. Is there a way to do this using JFrame, or will I need to use something else, like AWT?

** edit: is there any way to do this while retaining the title, window control buttons, etc.?

+3
source share
3 answers

You will need to do the following on JFrame:

frame.setUndecorated(true);
+3
source

Guys, I looked at him a little, apparently, there is a method called setMinimumSize

Basically, all you have to do is add

Dimension minimumSize = new Dimension(50, 50);  
frame.setMinimumSize(minimumSize);`

, , 75x75, 75. , frame.setResizable(false)

, !

+1

but is there a way to do this so that you still save the tyler, window control buttons, etc.?

You can use Metal LAF, which includes a title bar:

JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame(...);
0
source

All Articles