2016-04-26 1 views
1

は道にJFrame::setResizable(boolean)作品を理解するための簡単なプログラムです:なぜサイズをfalseに設定すると、パディングが表示されるのですか?ここ

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); 

そして、これはそれが示しものです:私はframe.setResizable(true);frame.setResizable(false);を変更すると、以下のように

enter image description here

は、今では動作します(I再起動していない、起動直後):

enter image description here

質問:最初の例のパディングはどこから来ましたか?第2の例のように(すなわち、これらのパディングなしで)resizable = falseウィンドウを作成する方法。

答えて

1

は、それはあなたがsetResizablepack(私はこれをテストし、それが働いていた)の順序を変更した場合、問題はもう発生しないことを、このdiscussionから見えます。

だから、この順序でそれらを呼び出す:

1)

frame.setResizable(false); 

2)

frame.pack(); 
+0

クール、本当にありがとうございました! –

関連する問題