-
a graphic on a button???
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks