Tips for Tuning your Graphical User Interface

Though some developers do not like the Swing components, which is due to some optical flaws. But in fact, these flaws are caused by default settings that are maybe chosen a bit awkwardly. Some improvements require the SweenJet API, others can be done without it.

  1. UI-themes
  2. Splash screens
  3. Multi-line tooltips
  4. Text anti-aliasing

UI-themes: New fonts and colors

If you want to use other fonts or colors you may use UI-themes. Such a theme defines a default font, a default foreground and a default background color. Additionally, fonts/colors can be set for single component types.

A UI-theme can be defined in a simple property file:

# myThemeUI.properties
name=MyTheme

font=Arial-0-11

background=[245,245,250]
foreground=darkGray

TextField.background=white
TextArea.background=white
TextField.foreground=black
TextArea.foreground=black
ProgressBar.foreground=[153,153,255]
ToolTip.background=[234,234,255]
List.background=white
Now, the UI-theme can be applied. This must be done as soon as possible and before any components is initialized.
try {
    // Call this method before any component is initialized.
    SwingUtils.applyUITheme(
        getClass().getResource("/myThemeUI.properties"));
} catch (IOException ioe) {
    ioe.printStackTrace();
}

Splash screens

Splash screens give important feedback to the user. If such a screen pops up, the user knows that the application launches.
IconSplashScreen splashScreen = new IconSplashScreen();
splashScreen.setIcon(new ImageIcon(
              getClass().getResource("mySplashScreen.png")));
splashScreen.setVisible(true);

// Do some stuff that needs some time.
// ...
// ...

splashScreen.setVisible(false);

Multi-line tooltips

SweenJet provides a simple solution for the recurrent problem of tooltips that are too long.
UIManager.put("ToolTipUI",
    "org.municware.sweenjet.swing.AdvancedToolTipUI");
UIManager.put("AdvancedToolTipUI.preferredRowCharCount", 25);

Text anti-aliasing

Anti-aliasing makes text more comfortable to read. Fortunately, Swing supports anti-aliasing. You only have to set the system property swing.aatext to true.