1

Here is the simple program to understand the way JFrame::setResizable(boolean) works:

JFrame frame = new JFrame("Test");
JPanel p1 = new JPanel();
FlowLayout fl = new FlowLayout(FlowLayout.LEADING, 0, 0);

//Adding buttons
p1.setLayout(fl);
p1.setBackground(Color.BLACK);
p1.add(new JButton("1"));
p1.add(new JButton("1"));
p1.add(new JButton("1"));
p1.add(new JButton("1"));
p1.add(new JButton("1"));

//Adding to JFrame
frame.add(p1);
frame.pack();

//Here is where the problem comes
frame.setResizable(false);

//The rest...
frame.setLocationRelativeTo(null);
frame.setVisible(true);

And this is what it shows:

enter image description here

Now when I change frame.setResizable(false); to frame.setResizable(true); it works as follows (I didn't do any resizings, it's just after the startup) :

enter image description here

QUESTION: Where does the padding in the first example come from? How to make the resizable = false window as in the second example (i.e. without these paddings).

1 Answers1

1

It looks from this discussion, that the problem won't occur anymore if you change the order of setResizableand pack (I tested this and it worked).

So call them in this order :

1)

frame.setResizable(false);

2)

frame.pack();
Arnaud
  • 17,229
  • 3
  • 31
  • 44