Example
Components have various parameters that can be set for them. They vary from component to component, so a good way to see what parameters can be set for components is to start typing componentName.set
, and let your IDE's autocomplete (If you use an IDE) suggest methods. The default shortcut in many IDEs, if it doesn't show up automatically, is CTRL + Space
.
Common parameters that are shared between all components
Description | Method |
---|
Sets the smallest size that the component can be (only if the layout manager honors the minimumSize property) | setMinimumSize(Dimension minimumSize) |
Sets the biggest size that the component can be (only if the layout manager honors the maximumSize property) | setMaximumSize(Dimension maximumSize) |
Sets the perferred size of the component (only if the layout manager honors the preferredSize property) | setPreferredSize(Dimension preferredSize) |
Shows or hides the component | setVisible(boolean aFlag) |
Sets whether the component should respond to user input | setEnabled(boolean enabled) |
Sets the font of text | setFont(Font font) |
Sets the text of the tooltip | setToolTipText(String text) |
Sets the Backgroundcolor of the component | setBackground(Color bg) |
Sets the Foregroundcolor (font color) of the component | setForeground(Color bg) |
Common parameters in other components
Common Components | Description | Method |
---|
JLabel , JButton , JCheckBox , JRadioButton , JToggleButton , JMenu , JMenuItem , JTextArea , JTextField | Sets the text displayed | setText(String text) |
JProgressBar , JScrollBar , JSlider , JSpinner | Set's a numerical value between the component's min and max values | setValue(int n) |
JProgressBar , JScrollBar , JSlider , JSpinner | Set's the smallest possible value that the value property can be | setMinimum(int n) |
JProgressBar , JScrollBar , JSlider , JSpinner | Set's the biggest possible value that the value property can be | setMaxmimum(int n) |
JCheckBox , JToggleBox | Set's whether the value is true or false (Eg: Should a checkbox be checked?) | setSelected(boolean b) |