Skip to main content

Nimbus LAF and sizeVariant

2 replies [Last post]
Joined: 2008-12-17

Hi everybody.

I am trying to get a "mini"-sized JScrollBar using the putClientProperty("JComponent.sizeVariant", "mini") method. This method works well for some components but not for others.
The piece of code above shows that the method is efficient for a JProgressBar, but not for a JButton (only the text is in "mini") and a JscrollBar.

<br />
import java.awt.BorderLayout;<br />
import javax.swing.JButton;<br />
import javax.swing.JFrame;<br />
import javax.swing.JProgressBar;<br />
import javax.swing.JScrollBar;<br />
import javax.swing.SwingUtilities;<br />
import javax.swing.UIManager;<br />
import javax.swing.UnsupportedLookAndFeelException;<br />
import javax.swing.WindowConstants;<br />
import javax.swing.UIManager.LookAndFeelInfo;</p>
<p>public class SizeVariantTest {</p>
<p>	public static void main(String args[]) throws Exception {<br />
		SwingUtilities.invokeAndWait(new Runnable() {<br />
			public void run() {<br />
				try {<br />
					for (LookAndFeelInfo info : UIManager<br />
							.getInstalledLookAndFeels()) {<br />
						if ("Nimbus".equals(info.getName())) {<br />
							UIManager.setLookAndFeel(info.getClassName());<br />
							break;<br />
						}<br />
					}<br />
				} catch (UnsupportedLookAndFeelException e) {<br />
					// handle exception<br />
				} catch (ClassNotFoundException e) {<br />
					// handle exception<br />
				} catch (InstantiationException e) {<br />
					// handle exception<br />
				} catch (IllegalAccessException e) {<br />
					// handle exception<br />
<p>				JFrame frame = new JFrame("Size Variant test");<br />
				frame.getContentPane().setLayout(new BorderLayout());</p>
<p>				frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);</p>
<p>				JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL);<br />
				scrollBar.putClientProperty("JComponent.sizeVariant", "mini");</p>
<p>				JButton button = new JButton("Press me");<br />
				button.putClientProperty("JComponent.sizeVariant", "mini");</p>
<p>				JProgressBar progressBar = new JProgressBar();<br />
				progressBar.putClientProperty("JComponent.sizeVariant", "mini");<br />
<p>				frame.getContentPane().add(progressBar, BorderLayout.NORTH);<br />
				frame.getContentPane().add(button, BorderLayout.CENTER);<br />
				frame.getContentPane().add(scrollBar, BorderLayout.SOUTH);</p>
<p>				frame.pack();<br />
				frame.setVisible(true);<br />
			}<br />
		});<br />
	}<br />

Is something wrong in my understanding of this feature of Nimbus ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-11-20

Note that it is only necessary to update the UI for those components that will have a different size.

I use the following idiom to created "variantSize" components:

T mini(T c) {
c.putClientProperty("JComponent.sizeVariant", "mini");
return c;

JButton button = mini(new JButton("Press me"));

Joined: 2010-04-07

the answer is here:

JFrame frame = ...;



Worked for me.