I have created customized Button. For that i have overrided paintComponenet method. How can I set Button Text on such button? I tried doing it using drawString method. But which x,y values should i give? (g.drawString("button text",x,y)). Please till me if anyone has handled this.
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
DefaultButtonModel bmodel = (DefaultButtonModel) super.getModel();
Image im = (new ImageIcon("image")).getImage();
System.out.println("im is "+im.getSource());
System.out.println("widthis" + im.getWidth(this));
int imageX = (getWidth() - im.getWidth(this)) /2;
int imageY = (getHeight() - im.getHeight(this)) / 2;
if(!super.isEnabled()) {
System.out.println("in disabled");
g.drawImage(disabled, imageX, imageY, this);
g.drawString( super.getText(), super.getX(),(int) (super.getY() / (1.9)));
}
else {
if(bmodel.isPressed()) {
System.out.println("in pressed");
g.drawImage(down, imageX, imageY, this);
} else if(bmodel.isRollover()) {
System.out.println("in roll overed");
g.drawImage(highlight, imageX, imageY, this);
} else if(bmodel.isEnabled()) {
System.out.println("in enabled");
g.drawImage(normal, imageX, imageY, this);
} else {
System.out.println("in else");
g.drawImage(normal, imageX, imageY, this);
}
g.drawString( super.getText(), super.getX(),(int) (super.getY() / (2.5)));
}
}