Java Reference
In-Depth Information
In this step, you may run into a couple of complications. The group Ȓblobsȓ tend
to vary in size more than the individual components. If you place them inside a
grid layout, the grid layout forces them all to be the same size. Also, you
occasionally would like a component from one group to line up with a
component from another group, but there is no way for you to communicate that
intent to the layout managers.
These problems can be overcome by using more sophisticated layout managers
or implementing a custom layout manager. However, those techniques are
beyond the scope of this topic. Sometimes, you may want to start over with Step
1, using a component layout that is easier to manage. Or you can decide to live
with minor imperfections of the layout. Don't worry about achieving the perfect
layoutȌafter all, you are learning programming, not user-interface design.
Step 5 Write the code to generate the layout.
This step is straightforward but potentially tedious, especially if you have a large
number of components.
Start by constructing the components. Then construct a panel for each
component group and set its l ayout manager if it is not a flow layout (the default
for panels). Add a border to the panel if required. Finally, add the components to
the panel. Continue in this fashion until you reach the outermost containers,
which you add to the frame.
800
801
Here is an outline of the code required for the pizza user interface.
JPanel radioButtonPanel = new JPanel();
radioButtonPanel.setLayout(new GridLayout(3, 1));
radioButton.setBorder(
new TitledBorder(new EtchedBorder(),
"Size"));
radioButtonPanel.add(smallButton);
radioButtonPanel.add(mediumButton);
radioButtonPanel.add(largeButton);
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.setLayout(new GridLayout(2, 1));
checkBoxPanel.add(pepperoniButton());
checkBoxPanel.add(anchoviesButton());
Search WWH ::




Custom Search