Home

Awesome

Darklaf - A themeable swing Look and Feel

CI Status Native Libraries Code Style Maven Central

This project is based on the darcula look and feel for Swing.

Screenshots

IntelliJDarcula
Solarized LightSolarized Dark
High Contrast LightHigh Contrast Dark

Usage & Features

A list of all features can be found here. The LaF is compatible with Java >=1.8 (you need >=1.9 to get proper scaling).

You can find all property values on weisj.github.io/darklaf-docs

This project is available on Maven Central:

Maven

<dependency>
  <groupId>com.github.weisj</groupId>
  <artifactId>darklaf-core</artifactId>
  <version>3.0.2</version>
</dependency>

Gradle

implementation("com.github.weisj:darklaf-core:3.0.2")

You can also use the latest nightly build.

repositories {
    maven {
        url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
    }
}

configurations.all {
    resolutionStrategy.cacheChangingModulesFor(0, "seconds")
}

dependencies {
    implementation("com.github.weisj:darklaf-core:latest.integration")
}

Installation

The LookAndFeel can be easily installed using the LafManager

// For default theme (IntelliJ)
LafManager.install();
// Specify explicit theme.
LafManager.setTheme(new IntelliJTheme());
LafManager.install();
// Directly install theme
LafManager.install(new DarculaTheme());

For more information see the wiki.

Note: The recommended method is using the LafManager as it automatically handles reloading the ui.

Choosing a theme

It is highly encouraged to provide users more than one theme. Forcing users to use a light/dark theme because of personal preferences might be degrading their experience in certain situations. For the visually impaired darklaf provides a set of high contrast themes, HighContrastThemeLight and HighContrastThemeDark.

Darklaf supports detecting the system theme on macOS and Windows with the ability to automatically change the theme if the settings change.

// This returns the preferred theme of the system settings.
LafManager.themeForPreferredStyle(getPreferredThemeStyle());

The following settings are picked up by darklaf:

WindowsmacOSSetting
:ballot_box_with_check::ballot_box_with_check:Light/Dark mode
:ballot_box_with_check::ballot_box_with_check:High contrast mode
:ballot_box_with_check::ballot_box_with_check:Accent color
:ballot_box_with_check:Selection color
:ballot_box_with_check:Font size

You can use the ThemeSettings class with ThemeSettings#showSettingsDialog or ThemeSettings#getSettingsPanel to provide the user the most possible customization.

Example

import com.github.weisj.darklaf.LafManager;
import javax.swing.*;
import java.awt.*;

public class DarklafDemo {

    public static void main(final String[] args) {
         SwingUtilities.invokeLater(() -> {
            LafManager.install();

            JFrame frame = new JFrame("Darklaf - A themeable LaF for Swing");
            frame.setSize(600, 400);

            JButton button = new JButton("Click here!");

            JPanel content = new JPanel();
            content.add(button);

            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(content);
            frame.setVisible(true);
        });
    }
}

All custom component-variants and settings can be enabled by setting the appropriate client property of the component. They can be found here.

This LookAndFeel supports custom window decorations (only on Windows at this point). In contrast to most other LaFs the native window behaviour is not compromised giving a seamless experience that still looks native.

Extensions

Check out the darklaf-extension project for additional artifacts which add support for some third-party projects.

Build

./gradlew build

When building on Windows, you need a C++ toolchain installed to build native extension.

When building on macOS you need to have XCode (or the command line tools) installed to build the native extension.

If you want to build for platforms different from your machine the necessary binaries are automatically downloaded. For this you have to specify a valid GithubAccessToken using githubAccessToken property in your local gradle.properties file. The access token only needs to have the permission to read repositories.

You can also manually download the respective native libraries from the latest successful run of the Build Native Libraries Action and place it in the corresponding <variant>/libraries folder. This is necessary if you don't have the appropriate toolchain installed, but you machine is a binary target.

Note: You can still build the project without the libraries, but then custom decorations won't be supported.

Contribute

Here is a list of things that currently are not finished or need refinement. This list is a work in progress and being updated regulary. If you find any problems with the LaF feel free to submit an issue:

Artifacts

Projects using Darklaf

Please send me your project, and I'll add it here.

License

This project is licensed under the MIT license.