With this code the buttons align left, but the glue doesn’t expand.. I wanted buttons 2 and 3 to float right.
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);
In order to use
glue, you need to use a BoxLayout.