Linux's KDE defines themes that set the color scheme and style for window frames, tabs, buttons, and other components drawn by KDE's Qt user interface toolkit. For Java applications, changing the theme should set colors in Java's
java.awt.SystemColor objects, which applications may use to customize their user interfaces to match the current theme. Unfortunately, there are some problems here.
This article discusses
SystemColor problems with KDE, and provides color swatches, RGB/HSV values, and downloadable color lists for the default
SystemColors on Linux.
Table of Contents
This article is part of a series on How to use SystemColors to access OS user interface theme colors that catalogs Java's
SystemColors for user interface themes in major OSes. The color catalogs provide a resource for comparing theme colors and creating custom Java components that match the themes.
Accessing KDE theme colors from Java
A KDE theme defines the color scheme and style for window frames, buttons, and so on. Each Linux distribution comes with a starter set of themes. Additional themes can be downloaded from KDE-Look.org, including many that mimic the appearance of Mac, Windows, and Gnome themes.
In principal, Java's
java.awt.SystemColor class provides access to theme colors, such as the foreground and background colors for buttons, text fields, and menus. Each theme color has a static
SystemColor object. For instance,
SystemColor.textHighlight is the background color for selected text in a text field. Unfortunately, Java's GTK foundation clashes with KDE's Qt foundation and causes problems with Java access to theme colors.
A list of
SystemColor objects and their use is discussed further in the lead series article. The following article discusses rather substantial KDE-specific issues and provides color swatches and RGB values for the default
Selecting KDE themes
Briefly, KDE themes are controlled from the extensive Appearance page of the Configure Desktop control panel. The theme used for these screenshots is OpenSUSE's default Oxygen theme.
|Figure 1. Button style selections in the
KDE Style page of the Appearance control panel.
Button, tab, scrollbar, and other component styles are selected using the Style tab. The Windows tab selects among window frame styles, the Colors tab selects between color schemes, the Icons tab selects icon sets, and the Fonts tab selects fonts. All of these control panels have more of their own tabs and control panels to tweak everything from button sizes to window drop shadow offsets.
|Figure 2. Window style selections in the
KDE Windows page of the Appearance control panel.
|Figure 3. Color selections in the
KDE Colors page of the Appearance control panel.
Dealing with KDE SystemColor problems
SystemColor class is a flawed approach to accessing OS theme settings. While colors are defined for button backgrounds and text, none are defined for tabs, checkboxes, radio buttons, progress bars, and more. Though a highlight color is defined for selected text, none are defined for selected menu items, toggle buttons, radio buttons, or checkboxes. Beyond colors, Java has no access to OS theme fonts, button styles, window title bar buttons, and so forth. So, while there are specific problems on Linux (and every OS), the primary problem is that Java's theme access is flawed.
Java's user interface class libraries (
javax.swing) are implemented by Linux Java distributions such as Oracle's JDK, Oracle's JRocket, IBM's JDK, and the open source OpenJDK and Apache Harmony. On Linux, all of these are built atop the GTK+ user interface toolkit.
There are two big problems here:
- Java's user interface is drawn by GTK+ and not by KDE's Qt toolkit.
- Java's use of GTK+ is broken anyway.
All of the KDE theme control panels adjust settings for applications built using Qt. But Java uses GTK+ instead, so none of KDE's theme settings have any effect on Java applications... or any other GTK+ applications. There are so many Linux GTK+ applications (such as those designed to work with Gnome), that KDE provides a separate control panel for basic GTK+ theme control. These settings do affect Java applications.
|Figure 4. GTK theme selections in the
KDE GTK page of the Appearance control panel.
However... none of GTK+'s theme settings initialize Java's
SystemColors anyway. The
SystemColor feature is simply broken. This is a known bug in Java, but it has gone unfixed for years.
Instead, on Linux the
SystemColors are initialized to generic defaults that have nothing to do with the current KDE or Gnome theme, and they don't change when the theme is changed. Worse, the generic defaults depend upon the Java distribution in use. Oracle's JDK, Oracle's JRocket, IBM's JDK, and the OpenJDK all initialize the colors one way. Apache's Harmony initializes them another way.
There is a partial work-around. On Linux, the
UIDefaults for the native "GTK+" look and feel are set to the proper Gnome theme values, and they update as the theme is changed. These look and feel defaults can be accessed whether or not the Java application uses the look and feel.
However, because Java uses GTK+, and not Qt, there is no native Qt look and feel and no way for a Java application to get any of the KDE theme settings. The best you can do is use the GTK+ theme settings from Gnome.
Color swatches and values
While the problems in the
SystemColor implementation insure that the class has almost no use on Linux, the color swatches below nevertheless show the initialized (wrong) defaults for several Java distributions.
Oracle JDK, Oracle JRocket, OpenJDK, and IBM JDK
Oracle's JDK is the gold standard for Java implementations. OpenJDK is nearly the same, with Oracle's proprietary code removed. Oracle's older JRocket and IBM's JDK track these closely and initialize the
SystemColors identically (and incorrectly).
Apache's Harmony is an independent full implementation of Java. While it uses different, and more esthetically appealing
SystemColor defaults, those defaults are still wrong and don't track the OS theme.
Each Java implementation's default
SystemColor set is available as a download in the X11 rgb.txt file format:
- Oracle JDK, Oracle JRocket, OpenJDK, and IBM JDK:
- Apache Harmony: