Java 液体布局。。使按钮向右浮动

Java 液体布局。。使按钮向右浮动,java,swing,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)); JBu

使用此代码,按钮向左对齐,但胶水不会展开。。我想要按钮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);

要使用
胶水
,您需要使用BoxLayout.

或实例化。