Java Reference
In-Depth Information
172 else if (largeButton.isSelected())
173 size = LARGE_SIZE;
174
175 // Set font of text field
176
177 sampleField.setFont( new Font(facename,
style, size));
178 sampleField.repaint();
179 }
180
181 private JLabel sampleField;
182 private JCheckBox italicCheckBox;
183 private JCheckBox boldCheckBox;
184 private JRadioButton smallButton;
185 private JRadioButton mediumButton;
186 private JRadioButton largeButton;
187 private JComboBox facenameCombo;
188 private ActionListener listener;
189
190 private static final int FRAME_WIDTH = 300 ;
191 private static final int FRAME_HEIGHT =
400 ;
192 }
S ELF C HECK
3. What is the advantage of a JComboBox over a set of radio buttons?
What is the disadvantage?
4. Why do all user interface components in the FontViewerFrame
class share the same listener?
5. Why was the combo box placed inside a panel? What would have
happened if it had been added directly to the control panel?
798
799
H OW T O 18.1: Laying Out a User Interface
A graphical user interface is made up of components such as buttons and text
fields. The Swing library uses containers and layout managers to arrange these
components. This How To explains how to group components into containers
and how to pick the right layout managers.
Search WWH ::




Custom Search