Box.createRigidArea(Dimension d) has the following syntax.
public static Component createRigidArea(Dimension d)
In the following code shows how to use Box.createRigidArea(Dimension d) method.
import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; // w ww .ja va 2 s. co m import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class Main { public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = new Box(BoxLayout.Y_AXIS); rowOne.add(new JLabel("Username")); rowOne.add(Box.createRigidArea(new Dimension(20,20))); rowOne.add(new JTextField()); Component rowTwo = Box.createVerticalStrut(2); f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200); f.setVisible(true); } }