Page 778 - Introduction to Programming with Java: A Problem Solving Approach
P. 778
744 Chapter 17 GUI Programming—Component Layout, Additional GUI Components
4. setLayout(new FlowLayout(FlowLayout.RIGHT));
5. The five regions of a border layout are North at the top, South at the bottom, and West, Center, and East in a row between them.
6. True.
7. Zero or one.
8. add(new JLabel("Stop", SwingConstants.CENTER), BorderLayout.CENTER);
or
add(new JLabel("Stop", SwingConstants.CENTER));
9. False. Specify both values, for rows and columns, only if you know the number of rows and columns in your table and the table is completely filled in (i.e., there are no empty cells). Otherwise, specify just one dimension that you’re sure of and specify zero for the other dimension.
10. True.
11. Nothing. It does not change value.
12. JPanel containers are particularly useful with GridLayout and BorderLayout windows because each compartment in those layouts can store only one component. If you need a compartment to store more than one component, let that one component be a JPanel container, and put multiple components into the JPanel container.
13. The add(new JLabel()); statement adds a dummy component (a blank label) to the bottom-left cell. The dummy component is necessary because, without it, the xLogPanel would go into the bottom-left cell, and that’s inappropriate.Apago PDF Enhancer
14. True. JTextArea components are editable by default.
15. False. JTextArea components do not employ line wrap by default.
16. If you click a check box that’s already selected, the check box becomes unselected.
17. The following code creates a check box named attendance. The check box is pre-selected, and it has an “I will attend” label.
JCheckBox attendance = new JCheckBox("I will attend", true);
18. Nothing. It stays selected.
19. The clicked button becomes selected and all other buttons in the group become unselected.
20. Combo boxes and radio button groups are similar in that they both allow the user to select one item from a list of items.
21. To determine the current selection for a combo box, call either getSelectedItem or getSelectedIndex.
22. If the radioGroup code is omitted from the JobApplication program, the program still compiles and runs, but the radio buttons operate independently. In other words, clicking one radio button will not cause the other one to be unselected.
23. This statement adds a 20-pixel blank margin to a JPanel container named panel: panel.setBorder(new EmptyBorder(20, 20, 20, 20));
24. JSlider constructor call:
new JSlider(0, 50, 10);