Java Reference
In-Depth Information
frame.setLayout(new FlowLayout());
frame.add(panel1);
frame.add(panel2);
frame.add(panel3);
frame.pack();
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
An x-axis BoxLayout works similarly when all the components have the same vertical align-
ments. Instead of being left-, center-, and right-justified, the components would appear at the
top, center, and bottom of the container. Figure 10-10 demonstrates this appearance.
Figure 10-10. Three x-axis BoxLayout containers that each have components with the same
vertical alignments
The source for the example shown in Figure 10-10 requires just a few changes from
Listing 10-2. The complete source is provided in Listing 10-3.
Listing 10-3. X-Axis Alignment
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class XAxisAlignY {
private static Container makeIt(String title, float alignment) {
String labels[] = {"-", "-", "-"};
JPanel container = new JPanel();
container.setBorder(BorderFactory.createTitledBorder(title));
BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
container.setLayout(layout);
 
Search WWH ::




Custom Search