2

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:

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

Follow up:

enter image description here

  • 1
    Please do have a look at [HOW TO ADD IMAGES TO YOUR PROJECT](http://stackoverflow.com/a/9866659/1057230) and this [answer](http://stackoverflow.com/a/11372350/1057230) of mine – nIcE cOw Jul 19 '12 at 18:02

3 Answers3

2

You can find a good example in 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:

<imageIcon id="check_off" path="images/checkbox_off.png"/>

Where checkbox_off.png lives in demo.synth.images package.

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
  • Thank you. nice article. I have also modified my follow up section for better picture of this. –  Jul 23 '12 at 18:04
2
  1. please to check, especially answer by @trashgod shows basic stuff but with great code workaround for BasicXxxUI

  2. I'd be use Nimbus Look and Feel rather that prehistoric and plain Synth,

  3. Nimbus has similair issues with GUI, aaaaand a few Bugs moreover,

  4. Nimbus (based on plain Synt) could be easiest of ways and around us are a fews great hacks

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
0

You can also add XML file by passing whole path of file

for e.g.

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

Vighanesh Gursale
  • 921
  • 5
  • 15
  • 31