javalook-and-feelnetbeans-platformnetbeans-11

Setting Look and Feel for Netbeans Platform (RCP) Application


Netbeans recently added the FlatLaf look and feel which I would love to add to our Netbeans Platform (RCP) application. I saw a lot of threads describing how to add a look and feel to a simple java application, but the few that were concerned with adding it to a netbeans rcp application did not really offer a solution or had only dead links.

If I activate the "Tools -> Options -> Appearance" menu-entries in our application I can already activate the FlatLaf manually but I obviously would like to automatically do that when the application starts.

Does anyone know how to do this?

(Project is running under JDK11 and Netbeans RCP dependencies with version RELEASE113 (11.3) )


Solution

  • Add the following code in the validate() method of a ModuleInstall subclass, so that it's done very early during the startup process.

    NbPreferences.root().node("laf").put("laf", FlatDarkLaf.class.getName());
    UIManager.installLookAndFeel(new UIManager.LookAndFeelInfo("FlatLaf Dark", FlatDarkLaf.class.getName()));  
    

    To switch back to the default theme:

    NbPreferences.root().node("laf").remove("laf");
    

    For more complete code have a look to my application JJazzLab-X on GitHub, in the UISettings Netbeans module.