hi!
i want to put a graphic on a button, so that the hole button is filled with it.
(the jbutton is not what i'm looking for.)
has someone written an own class for it, or knows where i can find one?
xxx
Printable View
hi!
i want to put a graphic on a button, so that the hole button is filled with it.
(the jbutton is not what i'm looking for.)
has someone written an own class for it, or knows where i can find one?
xxx
One possible way to do that would be to make a class that extends the JButton, and override the public void paintComponent(Graphics g) class to display an image rather than the normal button. Don't call super.paintComponent(). One example of this could be:
public void paintComponent(Graphics g) {
Graphics2D g2 = Graphics2D(g);
g2.drawImage(new Image(getDefaultToolkit().getImage(getClass().getResource("testing.jpg"))),null,this);
}
I haven't tested this, so there might be an error or something...hope it helps, though. You might want to check out the Graphics2D tutorials from www.thejavatutorial.com for more help on drawing images...another way to get the image would be:
ImageIcon ii = new ImageIcon("testing.jpg")
g2.drawImage(ii.getImage(),null,this)