Jump to content

Synth Look and Feel

From Wikipedia, the free encyclopedia

synthis askinnableJavalook and feel,which is configured with anXMLproperty file.[1]

According to Sun, goals for synth were:

  • Enable to create custom look without writing any code.
  • Allow appearance to be configured from images.
  • Provide the ability to customize the look of a component based on its named properties.
  • Provide a centralized point for overriding the look of all components.
  • Enable custom rendering based on images, or user-definedSynthPainters.

History

[edit]

synth is available beginning with versionJ2SE 5.0of Java (seeJava version history).[2]

Java SE 6 Update 10release and newer containNimbus,a cross-platform Look and Feel implemented with Synth. However, for backwards compatibility, Metal is still the default Swing look and feel.[3]

Architecture

[edit]

Synth is a skinnable look and feel in which all painting is delegated to the components, without having to write any code (seeSynth Look and Feel).[4]

However synth does not provide a default look, and components that are not defined in the synthXMLfile will not be painted. It is however possible to assign a default style to all other widgets, and customize styles for some specific widgets only.

Example

[edit]

The following XML declaration defines a style named textfield and binds it to all text fields. ThedefaultStyleallows to set a default font, foreground and background colors to all other widgets.

<synth>
<styleid="defaultStyle">
<fontname="Verdana"size="16"/>
<state>
<colorvalue="WHITE"type="BACKGROUND"/>
<colorvalue="BLACK"type="FOREGROUND"/>
</state>
</style>
<bindstyle="defaultStyle"type="region"key=".*"/>
<styleid="textfield">
<state>
<colorvalue="yellow"type="BACKGROUND"/>
</state>
<imagePaintermethod="textFieldBorder"path="textfieldborder.png"
sourceInsets="5 6 6 7"paintCenter="false"/>
<insetstop="5"left="6"bottom="6"right="7"/>
</style>
<bindstyle="textfield"type="region"key="TextField"/>
</synth>

Supposing that the XML declaration is defined in a file namedsynthExample.xml,the following code loads the XML definition file and sets the current look and feel to synth (loading a synth Look and Feel is done using theloadmethod of theSynthLookAndFeelclass):

SynthLookAndFeellaf=newSynthLookAndFeel();
laf.load(newFile("synthExample.xml").toURI().toURL());
UIManager.setLookAndFeel(laf);

See also

[edit]

References

[edit]
  1. ^Scott Violet (2004-03-26)."The Synth Look and Feel".javadesktop.org.Retrieved2013-03-09.Synth is new and provides for the description of the look and feel through an external XML file.
  2. ^"Taming Tiger: Ocean and Synth meet Metal".IBM.2004-10-19.Retrieved2012-11-13.Synth is new and provides for the description of the look and feel through an external XML file.
  3. ^"Nimbus Look and Feel (The Java Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)".Sun Microsystems.Retrieved2010-07-01.
  4. ^"Advanced Synth".IBM.2005-02-01.Retrieved2012-11-13.Synth lets developers rapidly create and deploy custom looks for an application by introducing the concept of a "skin" to Java UI programming
[edit]