Java Reference
In-Depth Information
Note that although vertical struts have zero width, they have no maximum width so they can expand ho-
rizontally to have a width that takes up any excess space. Similarly, the height of a horizontal strut expands
when excess vertical space is available.
A vertical strut is returned as an object of type Component by the static createVerticalStrut() method
in the Box class. The argument to the method specifies the height of the strut in pixels. To create a horizontal
strut, you use the createHorizontalStrut() method.
You can space out the radio buttons in the previous example by inserting struts between them:
// Create left column of radio buttons
Box left = Box.createVerticalBox();
left.add(Box.createVerticalStrut(30)); // Starting space
ButtonGroup radioGroup = new ButtonGroup(); // Create button group
JRadioButton rbutton; // Stores a button
radioGroup.add(rbutton = new JRadioButton("Red")); // Add to group
left.add(rbutton); // Add to Box
left.add(Box.createVerticalStrut(30));
// Space between
radioGroup.add(rbutton = new JRadioButton("Green"));
left.add(rbutton);
left.add(Box.createVerticalStrut(30));
// Space between
radioGroup.add(rbutton = new JRadioButton("Blue"));
left.add(rbutton);
left.add(Box.createVerticalStrut(30)); // Space between
radioGroup.add(rbutton = new JRadioButton("Yellow"));
left.add(rbutton);
Search WWH ::




Custom Search