Mega Code Archive

 
Categories / Java Tutorial / Swing
 

BoxLayout

import java.awt.Dimension; import java.awt.Insets; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class RigidArea {   public static void main(String[] args) {     JPanel panel = new JPanel();     panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));     panel.setBorder(new EmptyBorder(new Insets(40, 60, 40, 60)));     panel.add(new JButton("Button"));     panel.add(Box.createRigidArea(new Dimension(0, 5)));     panel.add(new JButton("Button"));     panel.add(Box.createRigidArea(new Dimension(0, 5)));     panel.add(new JButton("Button"));     panel.add(Box.createRigidArea(new Dimension(0, 5)));     panel.add(new JButton("Button"));     JFrame f = new JFrame();     f.add(panel);     f.pack();     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     f.setLocationRelativeTo(null);     f.setVisible(true);   } }