Setting Look and Feel for Netbeans Platform (RCP) Application

591 Views Asked by At

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) )

2

There are 2 best solutions below

14
On BEST ANSWER

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.

0
On

To anyone who might want to try the solution of jjazzboss: It works like a charm so long as you add the following dependency (which I forgot):

<dependency>
    <groupId>org.netbeans.api</groupId>
    <artifactId>org-netbeans-libs-flatlaf</artifactId>
    <version>${netbeans.version}</version>
</dependency>