我正在尝试synth风格,我遇到了以下问题,在经过相当多的研究后,我还没有找到答案。我有以下xml文件
<?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对象加载
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();
}
}当我尝试运行这段代码时,我得到了以下异常
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: You must supply an InputStream, StyleFactory and Class or URL任何关于如何解决这个问题的建议都非常受欢迎。
发布于 2012-11-27 05:53:30
你可以在Advanced Synth中找到一个很好的例子。
您可以在示例中看到:
SynthLookAndFeel synth = new SynthLookAndFeel();
synth.load(SynthFrame.class.getResourceAsStream("demo.xml"), SynthFrame.class);
UIManager.setLookAndFeel(synth);demo.xml位于demo.synth包中,与SynthFrame类相同,其中包含一些图像:
<imageIcon id="check_off" path="images/checkbox_off.png"/>demo.synth.images包中checkbox_off.png所在的位置。
我希望这能对你有所帮助。
发布于 2013-02-26 22:33:58
主类:
lookAndFeel.load(TestRApp.class.getResourceAsStream(synthFile),SynthLookAndFeel lookAndFeel =
TestRApp.class();new TestRApp.class);UIManager.setLookAndFeel(lookAndFeel);
synth.xml文件
<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"/>
https://stackoverflow.com/questions/13573579
复制相似问题