Synth
SYNTH is a newly introduced SWING component in J2SE5.0. SYNTH is a user-defined interface tool (generally referred to as SKINNABLE). User-defined SKIN (you call it skin) is controlled by an XML file. This way we don't have to rely on UIManager to write a property sheet (in fact, it is a constant of COPY to place the constant to adjust the properties) to control the appearance of the interface. We only need to adjust the part definition in the XML file above, basically save the work written by the code.
The following is a simple example, - from sun java Forum import java.awt.BorderLayout; import java.awt.EventQueue; import java.io.InputStream; import java.text.ParseException; import javax.swing.JButton; import Javax.swing.jlabel; import javax.swing.jframe; import static javax.swing.jframe. *; import javax.swing.uimanager; import javax.swing.plaf.synth.synthlookfeel;
public class HelloSynth {public static void main (String args []) {Runnable runner = new Runnable () {public void run () {SynthLookAndFeel synth = new SynthLookAndFeel (); try {Class aClass = HelloSynth.class; InputStream is = aClass .getResourceceasstream ("synth.xml"); if (is == null) {system.err.println ("missing configuration file"); system.exit (-1);} Synth.Load (is, aclass);} catch (ParseException e) {System.err.println ( "Bad configuration file"); System.exit (-2);} try {UIManager.setLookAndFeel (synth);} catch (javax.swing.UnsupportedLookAndFeelException e) {System. Err.Println ("Cannot Change To Synth"); System.exit (-3); JFrame Frame = New Jframe ("First"); Frame.SetDefaultCloseOperation (exit_on_clos E); jlabel label = new Jlabel ("Hello, Synth"); label.sethorizontalalignment (jlabel.center); frame.Add (Label); frame.setsize (300, 100); frame.setVisible (TRUE);}} EventQueue.invokelater (Runner);}}} Hellosynth created a new SynthlookAndFeel object and read XML files with the Load method: Synth.xml. Note that both parameters of Synth.Load (InputStream, Class <", INPUTSTREAM do not need to be further explained, is to read the data stream of the XML file, Class is a data source class, which is of course Hellosynth's Instance: ACLASS.
Here is SYNTH.XML