Swing MCQ
Swing MCQ
A) java.awt
B) javax.swing
C) java.io
D) java.util Answer: B) javax.swing
A) JPanel
B) JButton
C) JFrame
D) JLabel Answer: C) JFrame
A) To display text
B) To manage layouts and contain other components
C) To handle events
D) To create menus Answer: B) To manage layouts and contain other components
A) show()
B) setVisible(true)
C) display()
D) render() Answer: B) setVisible(true)
A) A menu item
B) A clickable button
C) A text field
D) A container Answer: B) A clickable button
A) JLabel
B) JTextField
C) JRadioButton
D) Thread Answer: D) Thread
A) BorderLayout
B) FlowLayout
C) GridLayout
D) BoxLayout Answer: D) BoxLayout
A) setHint()
B) setToolTipText()
C) setToolTip()
D) setTooltipText() Answer: B) setToolTipText()
10. What is the default layout manager for a JFrame's content pane?
A) FlowLayout
B) GridLayout
C) BorderLayout
D) BoxLayout Answer: C) BorderLayout
A) JScrollPane
B) JScrollBar
C) JScrollPanel
D) JScroller Answer: A) JScrollPane
13. Which component allows users to select a single item from a dropdown list in Swing?
A) JComboBox
B) JList
C) JTextField
D) JRadioButton Answer: A) JComboBox
A) To set the default action when the user clicks the close button on the JFrame
B) To set the default size of the JFrame
C) To set the default layout of the JFrame
D) To set the default title of the JFrame Answer: A) To set the default action when the user clicks the close
button on the JFrame
A) JImage
B) JIcon
C) JLabel
D) JPicture Answer: C) JLabel (with an ImageIcon)
A) setEditable(false)
B) setReadOnly(true)
C) setEnabled(false)
D) setInputDisabled(true) Answer: A) setEditable(false)
18. Which component would you use to create a popup menu in Swing?
A) JMenu
B) JMenuItem
C) JPopupMenu
D) JMenuBar Answer: C) JPopupMenu
A) EventHandler
B) ActionListener
C) EventManager
D) EventQueue Answer: B) ActionListener
A) addComponent()
B) append()
C) add()
D) insert() Answer: C) add()
21. Which of the following components can be used to group multiple buttons in Swing?
A) ButtonGroup
B) JPanel
C) JButton
D) JRadioButton Answer: A) ButtonGroup
A) setEnabled(boolean)
B) setVisible(boolean)
C) setEditable(boolean)
D) setComponentEnabled(boolean) Answer: A) setEnabled(boolean)
A) setFrameTitle()
B) setTitle()
C) setWindowTitle()
D) setCaption() Answer: B) setTitle()
A) setToolTipText(String text)
B) setHintText(String text)
C) setToolTip(String text)
D) setTextToolTip(String text) Answer: A) setToolTipText(String text)
A) Vertical
B) Horizontal
C) Diagonal
D) Circular Answer: B) Horizontal
A) JTextArea
B) JLabel
C) JEditorPane
D) JList Answer: C) JEditorPane
31. Which of the following is a correct way to set the layout manager of a JPanel?
A) setLayoutManager(LayoutManager mgr)
B) setLayout(LayoutManager mgr)
C) setPanelLayout(LayoutManager mgr)
D) setComponentLayout(LayoutManager mgr) Answer: B) setLayout(LayoutManager mgr)
32. How do you create a button with both text and an icon in Swing?
A) By using the JIconButton class
B) By setting both text and an icon using JButton
C) By using a JLabel instead of JButton
D) By using two separate components for text and icon Answer: B) By setting both text and an icon using
JButton
33. Which layout manager arranges components in a grid of rows and columns?
A) GridLayout
B) FlowLayout
C) BorderLayout
D) CardLayout Answer: A) GridLayout
A) addItem(Object item)
B) add(Object item)
C) append(Object item)
D) insertItem(Object item) Answer: A) addItem(Object item)
A) JDialog
B) JFrame
C) JWindow
D) JPopup Answer: A) JDialog
41. Which method is used to display a dialog box for user input in Swing?
A) JDialog.show()
B) JOptionPane.showMessageDialog()
C) JOptionPane.showInputDialog()
D) JFrame.showInput() Answer: C) JOptionPane.showInputDialog()
A) JComboBox.setEditable(false)
B) JComboBox.setReadOnly(true)
C) JComboBox.disable()
D) JComboBox.setUneditable(true) Answer: A) JComboBox.setEditable(false)
A) doClick()
B) click()
C) performClick()
D) press() Answer: A) doClick()
45. Which of the following components allows for the display of a list of choices in Swing?
A) JComboBox
B) JList
C) JTextArea
D) JTextField Answer: B) JList
A) addSeparator()
B) addLine()
C) addDivider()
D) insertSeparator() Answer: A) addSeparator()
49. Which Swing component can be used to display a selectable list of hierarchical data?
A) JTree
B) JTable
C) JComboBox
D) JTextArea Answer: A) JTree
50. Which method is used to close a JFrame when the close button is clicked?
A) setCloseOperation(JFrame.EXIT_ON_CLOSE)
B) setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
C) closeFrame()
D) dispose() Answer: B) setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
A) refresh()
B) repaint()
C) reload()
D) redraw() Answer: B) repaint()
A) JTextArea
B) JLabel
C) JTextPane
D) JPasswordField Answer: B) JLabel
A) To allow the user to input a numeric value with increment and decrement buttons
B) To create a progress bar
C) To select a color
D) To display a list of items Answer: A) To allow the user to input a numeric value with increment and
decrement buttons
56. Which layout manager would you use to create a UI with a fixed number of equally sized components?
A) GridLayout
B) FlowLayout
C) BorderLayout
D) BoxLayout Answer: A) GridLayout
A) addMouseListener()
B) addClickListener()
C) setMouseClick()
D) enableMouseEvents() Answer: A) addMouseListener()
58. Which Swing component is typically used to create a horizontal or vertical split in a window?
A) JSplitPane
B) JDivider
C) JScrollPane
D) JSeparator Answer: A) JSplitPane
A) scrollToTop()
B) setScrollPosition(0)
C) getViewport().setViewPosition(new Point(0, 0))
D) scrollToBeginning() Answer: C) getViewport().setViewPosition(new Point(0, 0))
60. Which of the following is used to create a password input field in Swing?
A) JTextField
B) JPasswordField
C) JTextPane
D) JTextArea Answer: B) JPasswordField