Java Box create horizontal box

Description

Java Box create horizontal box

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  ww  w . j av  a2 s  .  c o  m*/
        frame.setVisible(true);
    }
}



PreviousNext

Related