Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在xml文件中使用SynthLookAndFeel,其中xml文件路径将使用getResourceAsStream方法加载文件?_Java_Swing_Jslider_Synth - Fatal编程技术网

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

Java 如何在xml文件中使用SynthLookAndFeel,其中xml文件路径将使用getResourceAsStream方法加载文件?,java,swing,jslider,synth,Java,Swing,Jslider,Synth,我正在使用 SynthLookAndFeel laf = new SynthLookAndFeel(); laf.load(MyJSlider.class.getResourceAsStream("/ui/demo.xml"), MyJSlider.class); //laf.load(new URL("file:///var/tmp/demo.xml")); 其中my demo.xml包含以下内容: <style id="SliderTrackStyle">

我正在使用

SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(MyJSlider.class.getResourceAsStream("/ui/demo.xml"), MyJSlider.class);      
//laf.load(new URL("file:///var/tmp/demo.xml"));
其中my 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" />
避免和减少风险

如何像
path=Menu.class.getResourceAsStream(“/image/Menu/bg.jpg”)
那样使用它,以避免使用示例中所示的静态路径

跟进:


您可以在中找到一个很好的例子

您可以在示例中看到:

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\u off.png
位于
demo.synth.images
包中。

您可以在中找到一个很好的示例

您可以在示例中看到:

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\u off.png
位于
demo.synth.images
包中

  • 请特别回答
    @trashgood
    显示了基本的东西,但有针对BasicxxUI的强大代码解决方案

  • 我会使用
    Nimbus的外观和感觉
    ,而不是史前和普通的
    Synth

  • Nimbus
    在GUI、AAAAA和一些bug方面也存在类似的问题

  • Nimbus
    (基于普通的
    Synt
    )可能是最简单的方法,我们周围有很多很棒的黑客

  • 请特别回答
    @trashgood
    显示了基本的东西,但有针对BasicxxUI的强大代码解决方案

  • 我会使用
    Nimbus的外观和感觉
    ,而不是史前和普通的
    Synth

  • Nimbus
    在GUI、AAAAA和一些bug方面也存在类似的问题

  • Nimbus
    (基于普通的
    Synt
    )可能是最简单的方法,我们周围有很多很棒的黑客


  • 您还可以通过传递文件的整个路径来添加XML文件

    例如

    SynthLookAndFeel laf = new SynthLookAndFeel();
    laf.load(new URL("file:///D:/Demo/src/example1.xml"));
    UIManager.setLookAndFeel(laf);
    

    它对我有用。为您的应用程序试用它

    您还可以通过传递文件的整个路径来添加XML文件

    例如

    SynthLookAndFeel laf = new SynthLookAndFeel();
    laf.load(new URL("file:///D:/Demo/src/example1.xml"));
    UIManager.setLookAndFeel(laf);
    

    它对我有用。试一下你的应用程序

    请看一看我的这个请看一看我的这个谢谢。好文章。我还修改了我的后续部分,以便更好地了解这一点。谢谢。好文章。为了更好地了解这一点,我还修改了我的后续部分。