简体   繁体   English

如何在XML文件中使用SynthLookAndFeel,其中xml文件路径将使用getResourceAsStream方法加载文件?

[英]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包中。

  1. please to check , especially answer by @trashgod shows basic stuff but with great code workaround for BasicXxxUI 检查一下 ,特别是@trashgod回答显示了基本内容,但是具有针对BasicXxxUI的出色代码解决方法

  2. I'd be use Nimbus Look and Feel rather that prehistoric and plain Synth , 我会用Nimbus Look and Feel而不是史前和普通的Synth

  3. Nimbus has similair issues with GUI, aaaaand a few Bugs moreover, Nimbus在GUI,aaa和一些Bug方面存在类似问题,

  4. 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.

相关问题 如何使用getResourceAsStream读取XML文件 - How to read a XML file using getResourceAsStream 无法使用getResourceAsStream加载文件 - Cannot Load the file using getResourceAsStream URI不是分层的。 如何使用getResourceAsStream获取文件路径 - URI is not hierarchical. How to get File Path using getResourceAsStream XML解析(StAX)| xml文件中的getResourceAsStream返回null - XML Parsing (StAX)| getResourceAsStream from xml file returns null 如何使用PropertyPlaceholderConfigurer使用自定义xml文件将变量加载到我的spring.xml中? - How to use a custom xml file to load variables to my spring.xml using PropertyPlaceholderConfigurer? 有没有办法使用 getResourceAsStream 方法读取数据目录路径中存在的 json 文件? - Is there a way to use getResourceAsStream method to read a json file present in data directory path? 无法从绝对路径加载xml文件 - Unable to load xml file from a absolute path 如何使用Android在本地(.cpp文件)中加载xml文件 - How to Load xml file in native(.cpp file) using android 使用getResourceAsStream使用他的完整路径读取Android文件 - Using getResourceAsStream to read an Android file using his full-path getResourceAsStream(file)在哪里搜索文件? - Where does getResourceAsStream(file) search for the file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM