Hallo,
ich habe eine eigene Klasse, abgeleitet von JLabel
Da bekomme ich jetzt eine NullPointerException. Ich vermute dass es evtl. an dem this.getGraphics liegt, was ja im Konstruktor über getStringBounds() aufgerufen wird.
Was ich will ist, dass wenn TextLink erzeugt wird, automatisch bounds gefüllt wird.
Kann mir da jemand helfen?
Danke Sneedle
ich habe eine eigene Klasse, abgeleitet von JLabel
Java:
public class TextLink extends JLabel {
Rectangle2D bounds;
int posX;
int posY;
...
public TextLink(String text, Font f, int x, int y) {
//Konstruktor
this.setText(text);
this.setFont(f);
posX = x;
posY = y;
getStringBounds();
}
private void getStringBounds() {
//zur ermittlung von Breite und Höhe des Textes in Bezug auf einen
//bestimmten Font
FontMetrics metrics = this.getGraphics().getFontMetrics();
bounds = metrics.getStringBounds(this.getText(), this.getGraphics());
}
...
}
Da bekomme ich jetzt eine NullPointerException. Ich vermute dass es evtl. an dem this.getGraphics liegt, was ja im Konstruktor über getStringBounds() aufgerufen wird.
Was ich will ist, dass wenn TextLink erzeugt wird, automatisch bounds gefüllt wird.
Kann mir da jemand helfen?
Danke Sneedle