Is it possible to set fixed width for JFrame? At least the following code isn't working:
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
public final class Main {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500, 500);
f.setMinimumSize(new Dimension(500, 0));
f.setMaximumSize(new Dimension(500, Integer.MAX_VALUE));
f.setVisible(true);
}
});
}
}
The minimum setting is working but the maximum is not.
Use f.setPreferredSize(new Dimension(500, 500));
in your code.
And definitely read this post : Java: Difference between the setPreferredSize() and setSize() methods in components
And to prevent your frame growing or shrinking use f.setResizable(false);
Set size then write:
JFrame.setResizable(false);
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