2017-10-03 15 views
1

BoxLayoutに2つのボタンがあるパネルがあります。私が望むのは、ボタンの間に垂直のスペースを追加することです。ここでBoxLayoutのJButton間に垂直方向のスペースを追加するには?

Sreenshot:

私のコードです:

frame = new JFrame("FreshPos baza podataka"); 
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);   

JPanel panel = new JPanel(); 
panel.setBounds(new Rectangle(0, 5, 0, 0)); 
panel.setAlignmentY(Component.BOTTOM_ALIGNMENT); 
frame.getContentPane().add(panel, BorderLayout.WEST);  
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 

panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));  

JButton btnNewButton_1 = new JButton("New button");  
panel.add(btnNewButton_1);    

JButton btnNewButton_2 = new JButton("New button");     
panel.add(btnNewButton_2); 
+0

https://docs.oracle.com /javase/tutorial/uiswing/layout/box.html – matt

答えて

1

2つのボタンの間にあるパネルには見えない垂直成分を追加します。

JButton btnNewButton_1 = new JButton("New button"); 
panel.add(btnNewButton_1); 

panel.add(Box.createVerticalStrut(50)); 

JButton btnNewButton_2 = new JButton("New button"); 
panel.add(btnNewButton_2); 
+0

Ty mister。私はこれを正解とします。 –

関連する問題