Java Swing Components - Detailed Reference Guide
JFrame - Main Application Window
Purpose:
- The main window container for Swing GUIs.
Constructors:
- JFrame()
- JFrame(String title)
Key Methods:
- setSize(int width, int height)
- setTitle(String title)
- setVisible(boolean b)
- setDefaultCloseOperation(int)
Tips:
- Use EXIT_ON_CLOSE to close the app on exit.
JPanel - Component Container
Purpose:
- Groups multiple components.
Constructors:
- JPanel()
- JPanel(LayoutManager layout)
Key Methods:
- add(Component c)
- setLayout(LayoutManager m)
- setBorder(Border b)
Java Swing Components - Detailed Reference Guide
Tips:
- Useful for layout management.
JLabel - Static Text Display
Purpose:
- Displays static text or images.
Constructors:
- JLabel()
- JLabel(String text)
- JLabel(Icon icon)
Key Methods:
- setText(String text)
- setIcon(Icon icon)
JTextField - Single Line Text Input
Purpose:
- Allows user input in one line.
Constructors:
- JTextField()
- JTextField(String text)
- JTextField(int columns)
Key Methods:
- getText()
- setText(String text)
Java Swing Components - Detailed Reference Guide
JPasswordField - Hidden Input
Purpose:
- For password entry.
Constructors:
- Same as JTextField
Key Methods:
- getPassword()
- setEchoChar(char c)
JButton - Clickable Button
Purpose:
- Performs actions on click.
Constructors:
- JButton()
- JButton(String text)
Key Methods:
- addActionListener(ActionListener l)
- setEnabled(boolean b)
JToggleButton - Toggle State Button
Purpose:
- Toggle ON/OFF
Constructors:
Java Swing Components - Detailed Reference Guide
- JToggleButton(String text)
Key Methods:
- isSelected()
- setSelected(boolean b)
JTextArea - Multiline Text Input
Purpose:
- For multiline text.
Constructors:
- JTextArea()
- JTextArea(String text, int rows, int cols)
Key Methods:
- getText()
- append(String)
JScrollPane - Scroll View
Purpose:
- Adds scrolling.
Constructors:
- JScrollPane(Component view)
Key Methods:
- setVerticalScrollBarPolicy(int)
- setHorizontalScrollBarPolicy(int)
Java Swing Components - Detailed Reference Guide
JCheckBox - Multiple Option
Purpose:
- Select multiple choices.
Constructors:
- JCheckBox(String text)
Key Methods:
- isSelected()
- setSelected(boolean b)
JRadioButton - Single Choice
Purpose:
- Exclusive options.
Constructors:
- JRadioButton(String text)
Key Methods:
- isSelected()
- Use ButtonGroup for grouping.
JTable - Tabular Data
Purpose:
- Display tables.
Constructors:
- JTable(Object[][] data, Object[] columns)
Java Swing Components - Detailed Reference Guide
Key Methods:
- getValueAt(row, col)
- setValueAt(val, row, col)
JTabbedPane - Tab View
Purpose:
- Tabbed layout.
Constructors:
- JTabbedPane()
Key Methods:
- add(String title, Component comp)
- setSelectedIndex(int)
JList - List Display
Purpose:
- Show multiple items.
Constructors:
- JList(E[] items)
Key Methods:
- getSelectedValue()
- setListData(E[] data)
JComboBox - Drop-down Menu
Java Swing Components - Detailed Reference Guide
Purpose:
- Single selection drop-down.
Constructors:
- JComboBox(E[] items)
Key Methods:
- getSelectedItem()
- addItem(E item)
JSlider - Select Value
Purpose:
- Slider bar for values.
Constructors:
- JSlider(int min, int max, int value)
Key Methods:
- getValue()
- setMajorTickSpacing(int)
- setPaintTicks(true)
JTree - Hierarchical View
Purpose:
- Display tree structure.
Constructors:
- JTree(TreeNode root)
Java Swing Components - Detailed Reference Guide
Key Methods:
- expandRow(int)
- collapseRow(int)