使用此代码,按钮左对齐,但胶水不会扩展..我希望按钮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);
答案 0 :(得分:4)
要使用glue
,您需要使用BoxLayout。