液体布局..使按钮浮动正确

时间:2011-10-07 00:53:14

标签: java swing

使用此代码,按钮左对齐,但胶水不会扩展..我希望按钮2和3向右浮动。

frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
JPanel panelBottom = new JPanel();
frame.getContentPane().add(panelBottom, BorderLayout.SOUTH);
panelBottom.setLayout(new FlowLayout(FlowLayout.LEFT));

JButton btnNewButton = new JButton("1");
panelBottom.add(btnNewButton);

Component glue = Box.createGlue();
panelBottom.add(glue);

JButton btnNewButton_1 = new JButton("2");
panelBottom.add(btnNewButton_1);

JButton btnNewButton_2 = new JButton("3");
panelBottom.add(btnNewButton_2);

1 个答案:

答案 0 :(得分:4)

要使用glue,您需要使用BoxLayout。

相关问题