我正在尝试合成器风格,我遇到了以下问题,经过相当多的研究,一个避难所尚未找到答案。我有以下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
有关如何解决此问题的任何建议都非常受欢迎。
答案 0 :(得分:2)
您可以在Advanced Synth中找到一个很好的例子。
您可以在示例中看到:
SynthLookAndFeel synth = new SynthLookAndFeel();
synth.load(SynthFrame.class.getResourceAsStream("demo.xml"), SynthFrame.class);
UIManager.setLookAndFeel(synth);
并且demo.xml
位于demo.synth
包中,与SynthFrame
类相同,此XML包含一些图像:
<imageIcon id="check_off" path="images/checkbox_off.png"/>
checkbox_off.png
包含在demo.synth.images
包中。
我希望这可以帮到你。
答案 1 :(得分:0)
Main Calss:
SynthLookAndFeel lookAndFeel = new SynthLookAndFeel(); lookAndFeel.load(TestRApp.class.getResourceAsStream(synthFile), 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"/>