Text 2
Text 2
Chapter 13 topics:
36. Which Swing component would you use to create a menu bar with
dropdown menus?
• A) JMenu
• B) JMenuItem
• C) JMenuBar
• D) JPopupMenu
Answer: C) JMenuBar
37. If you want to add a keyboard shortcut (mnemonic) to a JMenuItem,
which method would you use?
• A) setAccelerator
• B) setShortcut
• C) setMnemonic
• D) setKeyBinding
Answer: C) setMnemonic
38. What does the setToolTipText method do when applied to a component?
• A) Adds a descriptive label above the component
• B) Adds an icon to the component
• C) Displays a small help text when hovering over the component
• D) Changes the text of the component
Answer: C) Displays a small help text when hovering over the component
39. Which of these classes would you use to create a slider that allows users
to select a value from a range?
• A) JProgressBar
• B) JScrollBar
• C) JSlider
• D) JRangeBar
Answer: C) JSlider
40. To change the appearance of a Swing application to look like a specific
operating system’s interface, which method should be used?
• A) UIManager.setAppearance()
• B) UIManager.setLookAndFeel()
• C) JComponent.setStyle()
• D) JFrame.setLook()
Answer: B) UIManager.setLookAndFeel()
41. Which method is used to set the label text of a JButton component?
• A) setText
• B) setLabel
• C) setButtonText
• D) setTitle
Answer: A) setText
42. Which of the following methods would you use to programmatically
select an item in a JComboBox?
• A) selectItem
• B) chooseItem
• C) setSelectedItem
• D) setSelection
Answer: C) setSelectedItem
43. If you need to retrieve the selected items from a JList in an array format,
which method would you use?
• A) getSelectedArray
• B) getItems
• C) getSelectedValuesList
• D) getSelection
Answer: C) getSelectedValuesList
44. Which Swing component should you use to let users open files or folders
from their system?
• A) JColorChooser
• B) JFileChooser
• C) JMenu
• D) JOptionPane
Answer: B) JFileChooser
45. In Java Swing, which method would you use to remove a selected item
from a JComboBox?
• A) removeItem
• B) deleteItem
• C) clearSelection
• D) deselectItem
Answer: A) removeItem
46. When adding a JLabel with an image, which constructor parameter is
used to specify the image?
• A) ImageIcon
• B) Image
• C) Picture
• D) Icon
Answer: A) ImageIcon
47. What is the return type of the getSelectedIndices method in JList?
• A) int
• B) Object[]
• C) int[]
• D) Integer[]
Answer: C) int[]
48. Which method would you use to add a new item to a JComboBox after it
has been created?
• A) addElement
• B) add
• C) addItem
• D) insertItem
Answer: C) addItem
49. What is the purpose of the JPanel class in Swing?
• A) To display images
• B) To contain and organize other components
• C) To create a drop-down list
• D) To display messages
Answer: B) To contain and organize other components
50. When using JMenu, which method is used to add individual menu items?
• A) addMenuItem
• B) addItem
• C) add
• D) appendItem
Answer: C) add
21. Which component would you use to let users choose a color in a GUI
application?
• A) JColorChooser
• B) JFileChooser
• C) JColorPicker
• D) JTextField
Answer: A) JColorChooser
22. What does getSelectedItem return when used with a JComboBox?
• A) The index of the selected item
• B) The selected item as a String
• C) The selected item as an Object
• D) The count of items in the combo box
Answer: C) The selected item as an Object
23. In the JList class, which method is used to display items from a new
array?
• A) addListData
• B) setData
• C) setListData
• D) updateList
Answer: C) setListData
24. Which of the following methods can be used to add tooltips to
components in Swing?
• A) setToolTipText
• B) setHint
• C) addTooltip
• D) showTooltip
Answer: A) setToolTipText
25. What is the purpose of the addListSelectionListener method in JList?
• A) To add items to the list
• B) To set a listener for handling selection events
• C) To remove items from the list
• D) To display the selected item
Answer: B) To set a listener for handling selection events
26. To retrieve multiple selected items as a list in JList, which method should
you use?
• A) getSelectedItems
• B) getSelectedValues
• C) getSelectedValuesList
• D) getAllSelectedItems
Answer: C) getSelectedValuesList
27. In JComboBox, which method would you use to make the first item in the
list appear by default?
• A) setSelectedItem
• B) setDefaultItem
• C) setSelectedIndex(0)
• D) selectItem
Answer: C) setSelectedIndex(0)
28. What does the setVisibleRowCount method in JList do?
• A) Sets the number of rows that can be selected
• B) Sets the maximum number of items that can be added
• C) Sets the number of items visible without scrolling
• D) Sets the index of the last visible item
Answer: C) Sets the number of items visible without scrolling
29. What type of event does JButton generate when clicked?
• A) Action event
• B) Mouse event
• C) Item event
• D) Selection event
Answer: A) Action event
30. Which method would you use to set the items displayed in a JComboBox
at runtime?
• A) addItems
• B) setData
• C) setComboData
• D) addItem
Answer: D) addItem
31. If you want a GUI component to display an image, which of these can be
used?
• A) JLabel
• B) JTextField
• C) JPanel
• D) JMenuItem
Answer: A) JLabel
32. What is the primary class used for creating dialog boxes to open or save
files?
• A) JFileSaver
• B) JFileChooser
• C) FilePicker
• D) JFileDialog
Answer: B) JFileChooser
33. In Java Swing, what method allows you to retrieve the text entered by the
user in a JTextField?
• A) getText
• B) getValue
• C) getString
• D) getInput
Answer: A) getText
34. Which component should you use if you need a scrollable text area?
• A) JTextField
• B) JScrollArea
• C) JTextArea inside a JScrollPane
• D) JTextBox
Answer: C) JTextArea inside a JScrollPane
35. What will getSelectedIndex return in a JComboBox if no item is selected?
• A) -1
• B) 0
• C) null
• D) It throws an exception
Answer: A) -1
These questions cover more advanced details and options in Java Swing,
providing a comprehensive review of Chapter 13 topics. Let me know if you need
further assistance!
Here’s a summary of the key concepts and optional questions for Chapter 13:
Key Concepts:
Let me know if you need additional details on any section or more specific
questions!
Here are additional multiple-choice questions to deepen understanding of
Chapter 13 topics:
These questions should cover the major concepts of Chapter 13 while giving
good practice on important topics. Let me know if you’d like more questions or
adjustments!