HI!
Ich habe ein bisschen mit Java synth herumexperimentiert.
Für einen Button verwende ich ein Hintergrungbild.
das bild liegt im Ordner "Projekt"/images/, heisst button.png
[XML]<synth>
<style id="basicStyle">
<font name="Comic Sans MS" size="17" style="BOLD"/>
<state>
<color value="WHITE" type="FOREGROUND"/>
</state>
</style>
<style id="buttonStyle">
<property key="Button.textShiftOffset" type="integer" value="1"/>
<insets top="5" left="5" right="5" bottom="5"/>
<state id="PRESSED">
</state>
<state id="MOUSE-OVER">
</state>
<state>
<imagePainter method="buttonBackground" path="images/button.png" sourceInsets="2 2 2 2"/>
</state>
</style>
<bind style="buttonStyle" type="region" key="button"/>
<bind style="basicStyle" type="region" key=".*"/>
</synth>
[/XML]
jetzt bekomme ich aber folgende fehlermeldung:
weiss jmd. Rat???
Ich habe ein bisschen mit Java synth herumexperimentiert.
Für einen Button verwende ich ein Hintergrungbild.
das bild liegt im Ordner "Projekt"/images/, heisst button.png
Java:
package test;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.text.ParseException;
import javax.swing.*;
import javax.swing.plaf.synth.*;
public class LookAndFeelTest extends JFrame {
/**
* @param args
*/
private Image img;
public LookAndFeelTest(){
super("Look And Feel Test");
img = new ImageIcon("images/background.png").getImage();
JPanel contentPane = new JPanel() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (img != null) {
g.drawImage(img, 0, 0, getWidth(), getHeight(), null);
}
}
};
JLabel text = new JLabel("TESTESTEST!!!");
JButton b = new JButton("Ich bin ein Button");
contentPane.add(text);
contentPane.add(b);
this.setContentPane(contentPane);
this.setSize(400,400);
this.setVisible(true);
}
public static void main(String[] args) throws UnsupportedLookAndFeelException, ParseException {
SynthLookAndFeel synth = new SynthLookAndFeel();
synth.load(LookAndFeelTest.class.getResourceAsStream("EMSoftLAF.xml"),LookAndFeelTest.class);
UIManager.setLookAndFeel(synth);
LookAndFeelTest testwnd = new LookAndFeelTest();
}
}
[XML]<synth>
<style id="basicStyle">
<font name="Comic Sans MS" size="17" style="BOLD"/>
<state>
<color value="WHITE" type="FOREGROUND"/>
</state>
</style>
<style id="buttonStyle">
<property key="Button.textShiftOffset" type="integer" value="1"/>
<insets top="5" left="5" right="5" bottom="5"/>
<state id="PRESSED">
</state>
<state id="MOUSE-OVER">
</state>
<state>
<imagePainter method="buttonBackground" path="images/button.png" sourceInsets="2 2 2 2"/>
</state>
</style>
<bind style="buttonStyle" type="region" key="button"/>
<bind style="basicStyle" type="region" key=".*"/>
</synth>
[/XML]
jetzt bekomme ich aber folgende fehlermeldung:
Java:
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(Unknown Source)
at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
weiss jmd. Rat???
Zuletzt bearbeitet von einem Moderator: