The one component that does not support the size variants property is
JLabel
. However, you can change the size of a label
by changing the size of its font.
You can set the size of a component with one line of code, before the component is displayed. The following snippet shows how to use each size:
// mini myButton.putClientProperty("JComponent.sizeVariant", "mini"); // small mySlider.putClientProperty("JComponent.sizeVariant", "small"); // large myTextField.putClientProperty("JComponent.sizeVariant", "large");
SwingUtilities.updateComponentTreeUI(Component)
method before the window is displayed. The following code
snippet updates the window and all the components it contains:
JFrame frame = ...; SwingUtilities.updateComponentTreeUI(frame); frame.pack(); frame.setVisible(true);