Java Box.createHorizontalStrut(int width)
Syntax
Box.createHorizontalStrut(int width) has the following syntax.
public static Component createHorizontalStrut(int width)
Example
In the following code shows how to use Box.createHorizontalStrut(int width) method.
import java.awt.BorderLayout;
import java.awt.Component;
/*w w w. j a va 2 s. co m*/
import javax.accessibility.AccessibleContext;
import javax.swing.Box;
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 = Box.createHorizontalBox();
rowOne.add(new JLabel("Username"));
rowOne.add(new JTextField());
Component rowTwo = Box.createHorizontalStrut(2);
f.add(rowOne, BorderLayout.NORTH);
f.add(rowTwo, BorderLayout.SOUTH);
f.setSize(300, 200);
f.setVisible(true);
}
}
Home »
Java Tutorial »
javax.swing »
Java Tutorial »
javax.swing »