2

I was searching if there is possible to change global size of all components in Nimbus Look and Feel.

There is a tutorial for re-sizing a component; but not for all components.

I've found something like this: http://www.jasperpotts.com/blog/2007/12/nimbus-large-small-mini-components/

November 6, 2008 at 11:29 am Sorry Matt there is no global setting for size, that is again something we could think about adding as it seems sensible.

but this post is from several years ago and maybe something has changed. Any ideas?

Thanks.

ring bearer
  • 20,383
  • 7
  • 59
  • 72
Arek Woźniak
  • 695
  • 3
  • 12
  • 25

3 Answers3

1

It can be done like this:

  UIManager.setLookAndFeel(new NimbusLookAndFeel());

  final SynthStyleFactory styleFactory = SynthLookAndFeel.getStyleFactory();
  SynthLookAndFeel.setStyleFactory(new SynthStyleFactory() {
    @Override
    public SynthStyle getStyle(JComponent c, Region id) {
      c.putClientProperty("JComponent.sizeVariant", "large");
      return styleFactory.getStyle(c, id);
    }
  });
Stijn
  • 69
  • 5
1

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);
    }
}
Rajeev Sreedharan
  • 1,753
  • 4
  • 20
  • 30
1

I do not think there is a nimbus specific way to achieve this. JXLayer project has implementation to transform the whole UI to different scales- This can be applied to any look and feel. You may want to check out this demo

ring bearer
  • 20,383
  • 7
  • 59
  • 72
  • Ok, thanks for your advice, but if there isn't simple way to achieve that in nimbus (without using 3rd party libraries like JXLayer) - I have to look for other laf. Any (free for commercial use) recommendation? – Arek Woźniak Apr 04 '12 at 06:51