首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在java中加载synth样式

如何在java中加载synth样式
EN

Stack Overflow用户
提问于 2012-11-27 05:38:53
回答 2查看 1.1K关注 0票数 1

我正在尝试synth风格,我遇到了以下问题,在经过相当多的研究后,我还没有找到答案。我有以下xml文件

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<synth>
    <style id="button">
        <state>
            <color value="blue" type="BACKGROUND"/>
            <color value="yellow" type="FOREGROUND"/>
        </state>
    </style>
    <bind style="button" type="region" key="Button"/>
</synth>

和下面的java代码将该xml文件作为SynthLookAndFeel对象加载

代码语言:javascript
复制
private void initializeStyle() {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    try {
        laf.load(this.getClass().getResourceAsStream("Style.xml"), this.getClass());
        UIManager.setLookAndFeel(laf);
    } catch (ParseException | UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }
}

当我尝试运行这段代码时,我得到了以下异常

代码语言:javascript
复制
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: You must supply an InputStream, StyleFactory and Class or URL

任何关于如何解决这个问题的建议都非常受欢迎。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-27 05:53:30

你可以在Advanced Synth中找到一个很好的例子。

您可以在示例中看到:

代码语言:javascript
复制
SynthLookAndFeel synth = new SynthLookAndFeel();
synth.load(SynthFrame.class.getResourceAsStream("demo.xml"), SynthFrame.class);
UIManager.setLookAndFeel(synth);

demo.xml位于demo.synth包中,与SynthFrame类相同,其中包含一些图像:

代码语言:javascript
复制
<imageIcon id="check_off" path="images/checkbox_off.png"/>

demo.synth.images包中checkbox_off.png所在的位置。

我希望这能对你有所帮助。

票数 2
EN

Stack Overflow用户

发布于 2013-02-26 22:33:58

主类:

lookAndFeel.load(TestRApp.class.getResourceAsStream(synthFile),SynthLookAndFeel lookAndFeel =

TestRApp.class();new TestRApp.class);UIManager.setLookAndFeel(lookAndFeel);

synth.xml文件

代码语言:javascript
复制
<style id="panelStyle">
    <imagePainter method="panelBackground" path="images/main-bg.png" sourceInsets="0 0 0 0" stretch="true"/>
</style>
<bind style="panelStyle" type="region" key="Panel"/>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13573579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档