[英]How to use SynthLookAndFeel with xml file, where xml file path will load the file using getResourceAsStream method?
I am using 我在用
SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(MyJSlider.class.getResourceAsStream("/ui/demo.xml"), MyJSlider.class);
//laf.load(new URL("file:///var/tmp/demo.xml"));
Where my demo.xml has following: 我的demo.xml具有以下内容:
<style id="SliderTrackStyle">
<opaque value="TRUE"/>
<state>
<imagePainter method="SliderTrackBackground" path="/var/tmp/JavaUnitTest/src/image/menu/bg.jpg" sourceInsets="0 0 0 0" />
</state>
</style>
<bind style="SliderTrackStyle" type="region" key="SliderTrack" />
Causes error: 导致错误:
run-single:
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:115)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:125)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:263)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
BUILD STOPPED (total time: 9 seconds)
To avoid and to have less risks. 避免和减少风险。
How can i use it like path=Menu.class.getResourceAsStream("/image/menu/bg.jpg")
where i wanted to avoid using the static path shown in example. 我该如何使用它,例如path=Menu.class.getResourceAsStream("/image/menu/bg.jpg")
,在这里我想避免使用示例中显示的静态路径。
Follow up: 跟进:
You can find a good example in Advanced Synth . 您可以在Advanced Synth中找到一个很好的例子。
You can see in the example that: 您可以在示例中看到:
SynthLookAndFeel synth = new SynthLookAndFeel();
synth.load(SynthFrame.class.getResourceAsStream("demo.xml"), SynthFrame.class);
UIManager.setLookAndFeel(synth);
And demo.xml
lives in demo.synth
package, the same of SynthFrame
class, where this XML contains: demo.xml
位于demo.synth
包中,与SynthFrame
类相同,该XML包含:
<imageIcon id="check_off" path="images/checkbox_off.png"/>
Where checkbox_off.png
lives in demo.synth.images
package. checkbox_off.png
位于demo.synth.images
包中。
please to check , especially answer by @trashgod
shows basic stuff but with great code workaround for BasicXxxUI 请检查一下 ,特别是@trashgod
回答显示了基本内容,但是具有针对BasicXxxUI的出色代码解决方法
I'd be use Nimbus Look and Feel
rather that prehistoric and plain Synth
, 我会用Nimbus Look and Feel
而不是史前和普通的Synth
,
Nimbus
has similair issues with GUI, aaaaand a few Bugs moreover, Nimbus
在GUI,aaa和一些Bug方面存在类似问题,
Nimbus
(based on plain Synt
) could be easiest of ways and around us are a fews great hacks Nimbus
(基于普通Synt
)可能是最简单的方式和我们周围是一个伟大的饥荒早期预警系统的黑客
You can also add XML file by passing whole path of file 您还可以通过传递文件的整个路径来添加XML文件
for eg 例如
SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(new URL("file:///D:/Demo/src/example1.xml"));
UIManager.setLookAndFeel(laf);
It works for me. 这个对我有用。 Try it for your application 尝试为您的应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.