The below answer is an extension of the previous answer by @Stijn with the change being in the initialization approach as recommended in the doc. Quoting the links nimbuslaf and swing tutorials - size
Version Note: Do not set the Nimbus look and feel explicitly by invoking the UIManager.setLookAndFeel method because not all versions
or implementations of Java SE 6 support Nimbus. Additionally, the
location of the Nimbus package changed between the JDK 6 Update 10 and
JDK 7 releases. Iterating through all installed look and feel
implementations is a more robust approach because if Nimbus is not
available, the default look and feel is used.
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
try {
Constructor c = Class.forName("MyStyleFactory").getConstructor(String.class);
c.newInstance("small"); // regular, mini, small or large
} catch (ExceptionInInitializerError eiie){
//
} catch (LinkageError le){
//
} catch (ClassNotFoundException cnfe){
//
}
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
}
File : MyStyleFactory.java
public class MyStyleFactory extends SynthStyleFactory {
protected static String variant = "regular";
final SynthStyleFactory styleFactory = SynthLookAndFeel.getStyleFactory();
static {
SynthLookAndFeel.setStyleFactory(new MyStyleFactory(variant));
}
public MyStyleFactory(String variant) {
if (variant.equals("regular") || variant.equals("mini")
|| variant.equals("small") || variant.equals("large"))
MyStyleFactory.variant = variant;
}
@Override
public SynthStyle getStyle(JComponent c, Region id) {
c.putClientProperty("JComponent.sizeVariant", variant);
return styleFactory.getStyle(c, id);
}
}