Reputation: 287
I've created a class extending JLabel, as normally it is not antialiased. But, when i use it, whole positioning of JLabel is broken. How is that possible? Here's the code for the class:
private class AntialiasedJLabel extends JLabel{
public AntialiasedJLabel(){}
public AntialiasedJLabel(String name){
this.setText(name);
}
public void paintComponent(Graphics g){
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.drawString(getText(),getX(),getY());
}
}
Here's the result using normal JLabel:
And here using AntialiasedJLabel:
What could be the problem here?
Upvotes: 1
Views: 87
Reputation: 324108
Don't do the custom painting yourself. Instead do:
Graphics g2 = g.create();
g2.setRenderingHint(...);
super.paintComponent(g2);
g2.dispose();
Upvotes: 3