我使用如何在xml文件中使用SynthLookAndFeel,其中xml文件路徑將使用getResourceAsStream方法加載文件?
SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(MyJSlider.class.getResourceAsStream("/ui/demo.xml"), MyJSlider.class);
//laf.load(new URL("file:///var/tmp/demo.xml"));
凡我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" />
導致錯誤:
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)
爲了避免和有較少的風險。
我如何使用它像path=Menu.class.getResourceAsStream("/image/menu/bg.jpg")
我想避免使用示例中顯示的靜態路徑。
追問:
請確實看看[如何添加圖像到您的項目](http://stackoverflow.com/a/9866659/1057230)和這[回答](http:// stackoverflow。 com/a/11372350/1057230)我的 – 2012-07-19 18:02:19