a graphic on a button???


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: a graphic on a button???

  1. #1
    Join Date
    Nov 2002
    Posts
    1

    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

  2. #2
    Join Date
    Nov 2002
    Posts
    59
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center