1. 新建一個工程,工程名為untitled1
2. 新建一個應用程序(File->New->Application)3. 在Frame1中添加一個按鈕
4. 在classesuntitled1目錄下添加圖象文件(1_Down.gif、1_Off.gif、1_On.gif,分別表示按鈕的三種狀態)和demo.XML文件
Demo.xml中的內容是:
<synth><?XML:NAMESPACE PREFIX = O />
<style id="button">
<state>
<imagePainter method="buttonBackground" path="images/1_On.gif"
sourceInsets="9 10 9 12" paintCenter="true" stretch="true"/>
<insets top="9" left="10" bottom="9" right="12"/>
<font name="Aharoni" size="16"/>
<color type="TEXT_FOREGROUND" value="#FFFFFF"/>
</state>
<state value="MOUSE_OVER">
<imagePainter method="buttonBackground" path="images/1_Down.gif"
sourceInsets="9 10 9 12" paintCenter="true" stretch="true"/>
<insets top="9" left="10" bottom="9" right="12"/>
<color type="TEXT_FOREGROUND" value="#FFFFFF"/>
</state>
<state value="PRESSED">
<imagePainter method="buttonBackground" path="images/1_Off.gif"
sourceInsets="10 12 8 9" paintCenter="true" stretch="true"/>
<insets top="10" left="12" bottom="8" right="9"/>
<color type="TEXT_FOREGROUND" value="#FFFFFF"/>
</state>
<property key="Button.margin" type="insets" value="0 0 0 0"/>
</style>
<bind type="region" key="Button"/>
</synth>
5. 在Application1.Java文件的頭部加入以下語句:
import javax.swing.plaf.synth.SynthLookAndFeel;
6. 對public void run()函數做如下的修改:
public void run() {
try {
//添加以下3個語句
SynthLookAndFeel synth = new SynthLookAndFeel();
synth.load(Application1.class.getResourceAsStream("demo.xml"),Application1.class);
UIManager.setLookAndFeel(synth);
/*原先的語句
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
*/
}
7. 編譯運行,便可看到結果了。
8. 其它控件的使用方法類似。