Synth is a skinnable look and feel in which all painting is delegated. Synth does not provide a default look. In order to use Synth you need to specify a file, or provide a {@link javax.swing.plaf.synth.SynthStyleFactory}. Both configuration options require an understanding of the synth architecture, which is described below, as well as an understanding of Swing's architecture.

Unless otherwise specified null is not a legal value to any of the methods defined in the synth package and if passed in will result in a NullPointerException.

Synth

Each {@link javax.swing.plaf.ComponentUI} implementation in Synth associates itself with one {@link javax.swing.plaf.synth.SynthStyle} per {@link javax.swing.plaf.synth.Region}, most Components only have one Region and therefor only one SynthStyle. SynthStyle is used to access all style related properties: fonts, colors and other Component properties. In addition SynthStyles are used to obtain {@link javax.swing.plaf.synth.SynthPainter}s for painting the background, border, focus and other portions of a Component. The ComponentUIs obtain SynthStyles from a {@link javax.swing.plaf.synth.SynthStyleFactory}. A SynthStyleFactory can be provided directly by way of {@link javax.swing.plaf.synth.SynthLookAndFeel#setStyleFactory(javax.swing.plaf.synth.SynthStyleFactory)}, or indirectly by way of {@link javax.swing.plaf.synth.SynthLookAndFeel#load}. The following example uses the SynthLookAndFeel.load() method to configure a SynthLookAndFeel and sets it as the current look and feel:

  SynthLookAndFeel laf = new SynthLookAndFeel();
  laf.load(MyClass.class.getResourceAsStream("laf.xml"), MyClass.class);
  UIManager.setLookAndFeel(laf);
      

Many JComponents are broken down into smaller pieces and identified by the type safe enumeration in {@link javax.swing.plaf.synth.Region}. For example, a JTabbedPane consists of a Region for the JTabbedPane ({@link javax.swing.plaf.synth.Region#TABBED_PANE}), the content area ({@link javax.swing.plaf.synth.Region#TABBED_PANE_CONTENT}), the area behind the tabs ({@link javax.swing.plaf.synth.Region#TABBED_PANE_TAB_AREA}), and the tabs ({@link javax.swing.plaf.synth.Region#TABBED_PANE_TAB}). Each Region of each JComponent will have a SynthStyle. This allows you to customize individual pieces of each region of each JComponent.

Many of the Synth methods take a {@link javax.swing.plaf.synth.SynthContext}. This is used to provide information about the current Component and includes: the {@link javax.swing.plaf.synth.SynthStyle} associated with the current {@link javax.swing.plaf.synth.Region}, the state of the Component as a bitmask (refer to {@link javax.swing.plaf.synth.SynthConstants} for the valid states), and a {@link javax.swing.plaf.synth.Region} identifying the portion of the Component being painted.

All text rendering by non-JTextComponents is delegated to a {@link javax.swing.plaf.synth.SynthGraphicsUtils}, which is obtained using the {@link javax.swing.plaf.synth.SynthStyle} method {@link javax.swing.plaf.synth.SynthStyle#getGraphicsUtils}. You can customize text rendering by supplying your own {@link javax.swing.plaf.synth.SynthGraphicsUtils}.

Notes on specific components

JTree

Synth provides a region for the cells of a tree: Region.TREE_CELL. To specify the colors of the renderer you'll want to provide a style for the TREE_CELL region. The following illustrates this:

  <style id="treeCellStyle">
    <opaque value="TRUE"/>
    <state>
      <color value="WHITE" type="TEXT_FOREGROUND"/>
      <color value="RED" type="TEXT_BACKGROUND"/>
    </state>
    <state value="SELECTED">
      <color value="RED" type="TEXT_FOREGROUND"/>
      <color value="WHITE" type="BACKGROUND"/>
    </state>
  </style>
  <bind style="treeCellStyle" type="region" key="TreeCell"/>

This specifies a color combination of red on white, when selected, and white on red when not selected. To see the background you need to specify that labels are not opaque. The following XML fragment does that:

  <style id="labelStyle">
    <opaque value="FALSE"/>
  </style>
  <bind style="labelStyle" type="region" key="Label"/>

JList and JTable

The colors that the renderers for JList and JTable use are specified by way of the list and table Regions. The following XML fragment illustrates how to specify red on white, when selected, and white on red when not selected:

  <style id="style">
    <opaque value="TRUE"/>
    <state>
      <color value="WHITE" type="TEXT_FOREGROUND"/>
      <color value="RED" type="TEXT_BACKGROUND"/>
      <color value="RED" type="BACKGROUND"/>
    </state>
    <state value="SELECTED">
      <color value="RED" type="TEXT_FOREGROUND"/>
      <color value="WHITE" type="TEXT_BACKGROUND"/>
    </state>
  </style>
  <bind style="style" type="region" key="Table"/>
  <bind style="style" type="region" key="List"/>