Over a million developers have joined DZone.
Platinum Partner

Themes for NetBeans Platform Applications

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

Today I found out, from David Strupl on the NetBeans Platform mailing list, that NetBeans Platform applications can have themes/skins defined, via XML files. That means that I hadn't read the Main class of the NetBeans Platform before, where I would have found the following method:

 public static void initUICustomizations() {
  if (!CLIOptions.isGui ()) {

  URL themeURL = null;
  boolean wantTheme = Boolean.getBoolean ("netbeans.useTheme") ||
      CLIOptions.uiClass != null && CLIOptions.uiClass.getName().indexOf("MetalLookAndFeel") >= 0;

  try {
      if (wantTheme) {
          //Put a couple things into UIDefaults for the plaf library to process if it wants
           FileObject fo = FileUtil.getConfigFile("themes.xml"); //NOI18N
           if (fo == null) {            
                // File on SFS failed --> try to load from a jar from path
                // /org/netbeans/core/startup/resources/themes.xml
                try {
                    themeURL = new URL("nbresloc:/org/netbeans/core/startup/resources/themes.xml"); //NOI18N
                    // check whether the file is there:
                } catch (IOException ex) {
                    themeURL = null;
           } else {
                try {
                    themeURL = fo.getURL();
                } catch (FileStateInvalidException fsie) {
                    //do nothing
  } finally {
      CoreBridge.getDefault ().initializePlaf(CLIOptions.uiClass, CLIOptions.getFontSize(), themeURL);
  if (CLIOptions.getFontSize() > 0 && "GTK".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
  StartLog.logProgress("Fonts updated"); // NOI18N

So, you can define a "themes.xml" file, in certain places, which the NetBeans Platform will then pick up and apply to the application. If you're not using Metal, then you need to provide a special setting to enable themes support.

Here's where I define my "themes.xml" file:

And all the definitions of the content of the file can be found here: http://ui.netbeans.org/docs/ui/themes/themes.html

Some sample themes are included, though they're not necessarily aesthetically pleasing, you can definitely see that something different happened to the application:

Where might themes be useful? Well, here's a themes file that could be pretty handy...

<themeset active="tableRows">

    <theme name="tableRows">
        <color key="Table.background1" r="170" g="144" b="119"/>
        <color key="Table.selectionBackground1" r="190" g="170" b="140"/>
        <color key="Table.background2" r="250" g="240" b="210"/>
        <color key="Table.selectionBackground2" r="198" g="183" b="157"/>


...since it results in the table rows below having alternate colors:

However, if you were using Nimbus, you wouldn't need the above theme, since Nimbus shows alternate colors out of the box:

In the case of Nimbus, and all other non-Metal look-and-feels, you need to (as can be read in the code at the top of this article) set "-J-Dnetbeans.useTheme=true" in the "platform.properties" of the application, if you want to use a themes file:

run.args.extra=--laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel -J-Dnetbeans.useTheme=true

The above will then enable a Nimbus look-and-feel to have a limited subset of theme definitions being available to it, such as these for enlarging the font:

Pretty cool that themes support is available and that it is fairly easy to apply them in this way.



The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}