How can I place an image on an AWT button?

Sandip Chitale

Subclass Button and override the paint method.


public void paint(Graphics g) {
  // call super's paint method
  super.paint(g);

  g.drawImage(...); // use any of the many drawImage variants here !
}

Most likely you will also have to override

public Dimension getPreferredSize()

public Dimension getMinimumSize()

public Dimension getMaximumSize()

also so that the layout managers can deal with the size of the Button correctly.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact