Nimbus Tweakings on the NetBeans Platform
Join the DZone community and get the full member experience.
Join For Free******** EDIT: 2011-02-19 ***************
Thanks to Geertjan's article I figured out how to make a complete redraw in real time.
Actually setting the UI to a different laf and then straight back again actually redraws the entire UI like I wanted to below.
public static void updateUI() {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception ex) {}
UIManager.put(nimbusBlueGrey, YOUR_NEW_COLOR);
SwingUtilities.updateComponentTreeUI(jFrame);
}
Strange, but it works.
************************************
Original story:
I'm just back from JFokus in Stockholm and a very good meeting with people sharing my NetBeans Platform interest. We might have been the only people at that steakhouse that particular evening, trading NetBeans advice... At that dinner I had the opportunity to show and discuss my current project's struggles with adopting the Nimbus Look & Feel to what our art director has created in photoshop.
The thing is that we want the user to be able to change his or her
settings in real time, so we want to change the Nimbus drawing properties
in real time programatically.
This can typically be done like this:
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()){
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
UIManager.put("nimbusBase", new Color(21, 21, 21));
UIManager.put("nimbusBlueGrey", new Color(44, 44, 44));
UIManager.put("control", new Color(40, 40, 40));
UIManager.put("textText", Color.WHITE);
jFrame = (JFrame) WindowManager.getDefault().getMainWindow();
SwingUtilities.updateComponentTreeUI(jFrame);
break;
}
}
In my current project, I run code similar like theabove in my "ModuleInstall" class, like this:
public void restored() {
WindowManager.getDefault().invokeWhenUIReady(new GuiInitialiser());
}
The code above is what gets done in the "GuiInitialiser".
However, and this is my main concern right now, this code behaves quite
differently when I, instead of setting the LAF programatically like the
above, set it by adding:
run.args.extra=--laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
...in my project's "platform.properties" file.
The problem seems to have something to do with performing a complete and clean redrawing of the entire project UI when setting it programatically.
To illustrate this, I have created a small project that illustrates what I'm talking about. If you run it, you will find that the main menubar at the top of the screen is quite ugly:
This is because I set
UIManager.put("nimbusBase", Color.MAGENTA);
UIManager.put("nimbusBlueGrey", Color.CYAN);
...before updating the UI the first time. However, changing the same properties after that does not redraw that part of the UI.
In this program, there are some predefined settings that you can try but
also a text field where you can try to change the color of any other Nimbus property
that you might like. However, due to the Nimbus logic of derived colors
(which by the way is illustrated quite well in the application above -
set "nimbusBase" to red and watch how red is implemented on, for instance,
the comboBox) it is quite hard to find a color property that just
instantly does what you want/expect it to.
So, if you're interested in this, you can download the project and play around with it. I hope that both the application and its source can benefit someone. Obviously, this application should have been presented as Java web start enabled, but that rendered even differently, which someone also should also feel very free to get back to me about...
So, if you like this, download it and experiment. Run it "as is" or with the LAF-setting in the "platform.properties" file instead. Run it as JNLP.
From http://henryaonnetbeans.blogspot.com
Opinions expressed by DZone contributors are their own.
Trending
-
Extending Java APIs: Add Missing Features Without the Hassle
-
RBAC With API Gateway and Open Policy Agent (OPA)
-
Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
-
The SPACE Framework for Developer Productivity
Comments