1. 新建一个工程,工程名为untitled1
2. 新建一个应用程序(file->new->application)
3. 在frame1中添加一个按钮
4. 在classes/untitled1目录下添加图象文件(1_down.gif、1_off.gif、1_on.gif,分别表示按钮的三种状态)和demo.xml文件
demo.xml中的内容是:
<synth>
<style id="button">
<state>
<imagepainter method="buttonbackground" path="http://www.itus.cnimages/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="http://www.itus.cnimages/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="http://www.itus.cnimages/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 style="button" 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. 其它控件的使用方法类似。
trackback: http://tb.blog.csdn.net/trackback.aspx?postid=1501691
闽公网安备 35060202000074号