Search code examples
javamavenswinglook-and-feelflatlaf

Swing Flatlaf customized properties file


I have integrated the flatlaf look and feel library into my Swing application via Maven, specifically utilizing version 1.6.2 of FlatLaf.

Within my application, I've employed the existing theme named "flatlaflight.setup()". However, prior to this step, I introduced a properties file bearing the same name into the resources directory. This file was utilized to tailor the style parameters according to my requirements. Regrettably, the system is unable to retrieve the customizations specified within this properties file.

Registered the custom default source to FlatLightLaf.registerCustomDefaultsSource("src/main/resources"); also tried FlatLightLaf.registerCustomDefaultsSource("resources");


Solution

  • To use a FlatLaf properties file in a Maven project:

    1. The properties file name must match the used theme class name. E.g. FlatLightLaf.properties for class FlatLightLaf or FlatDarkLaf.properties for class FlatDarkLaf.
    2. Place the properties file under the Maven resources/themes folder (relative path: src/main/resources/themes).
    3. You must call the method below BEFORE setting the look and feel:
    FlatLaf.registerCustomDefaultsSource("themes"); // look for properties file in themes folder
    
    // setup theme later
    

    Note: A section of the documentation places the properties file in com/myapp/themes/MyDarkerLaf.properties which I don't recommend for a Maven project because your properties will be deleted when you generate a jar file for your program.

    Reference

    https://www.formdev.com/flatlaf/how-to-customize/#application_properties