Jump to content

Synth Look and Feel

From Alfawiki
Synth
Company typeSoftware component
IndustrySoftware development, User interface design
Founded2004; 22 years ago (2004)
FounderSun Microsystems
ProductsJava look and feel
ParentSun Microsystems

synth represents a skinnable Java look and feel that is defined through an external XML configuration file.[1]

Sun Microsystems designed synth with several objectives in mind:

  • Allowing customized appearances without programming.
  • Enabling visual configuration based on images.
  • Tailoring component styling through property-based rules.
  • Centralizing style overrides across all UI components.
  • Supporting custom rendering using images or user-defined painters.

History

Synth was first released as part of J2SE 5.0 (refer to Java version history).[2]

Starting with Java SE 6 Update 10, Nimbus was added—a cross-platform Look and Feel implemented using Synth technology. Despite this, Metal remains the default Swing look and feel to maintain compatibility with earlier versions.[3]

Architecture

Synth transfers all painting responsibilities to components without requiring custom code (refer to ).[4]

It does not include a built-in default appearance; components absent from the synth XML configuration remain unstyled. Nevertheless, a global default style can be specified, with particular styles applied to selected components.

Example

The following XML snippet defines a style called textfield specifically for text fields. The defaultStyle sets font attributes along with foreground and background colors for other interface elements:

<syntaxhighlight lang="xml">
<synth>
 <style id="defaultStyle">
   
   <state>
     <color value="WHITE" type="BACKGROUND"/>
     <color value="BLACK" type="FOREGROUND"/>
   </state>
 </style>
 <bind style="defaultStyle" type="region" key=".*"/>
 <style id="textfield">
   <state>
     <color value="yellow" type="BACKGROUND"/>
   </state>
   <imagePainter method="textFieldBorder" path="textfieldborder.png"
                 sourceInsets="5 6 6 7" paintCenter="false"/>
   <insets top="5" left="6" bottom="6" right="7"/>
 </style>
 <bind style="textfield" type="region" key="TextField"/>
</synth>
</syntaxhighlight>

If this XML content is saved as synthExample.xml, the following Java snippet demonstrates loading it and applying synth as the active look and feel using the class:

<syntaxhighlight lang="java">

SynthLookAndFeel laf = new SynthLookAndFeel(); laf.load(new File("synthExample.xml").toURI().toURL()); UIManager.setLookAndFeel(laf); </syntaxhighlight>

See also

External links

  1. ↑ Lua error in Module:Citation/CS1/Configuration at line 2123: attempt to index field '?' (a nil value).
  2. ↑ Lua error in Module:Citation/CS1/Configuration at line 2123: attempt to index field '?' (a nil value).
  3. ↑ Lua error in Module:Citation/CS1/Configuration at line 2123: attempt to index field '?' (a nil value).
  4. ↑ Lua error in Module:Citation/CS1/Configuration at line 2123: attempt to index field '?' (a nil value).