Java Box create horizontal glue

Description

Java Box create horizontal glue

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
    public static void main(String[] args) {
        JFrame frame = new JFrame("FlowLayout Nesting");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Box hBox = Box.createHorizontalBox(); 
        hBox.add(new JButton("First")); 
        hBox.add(Box.createHorizontalGlue()); 
        hBox.add(new JButton("Last")); 
        // Add JPanel to the content pane 
        frame.getContentPane().add(hBox);

        frame.pack();//from  w  ww .j  a v a2s .co  m
        frame.setVisible(true);
    }
}



PreviousNext

Related