i'm programming a application in JAVA with JBuilder and i need to know if it's possible to display a image.gif as background instead of the usual Color
...and if it's possible ... wath is the source code to program such a thing.....
Printable View
i'm programming a application in JAVA with JBuilder and i need to know if it's possible to display a image.gif as background instead of the usual Color
...and if it's possible ... wath is the source code to program such a thing.....
You may use Component.getGraphics() to get the Graphics object
and use Graphics.drawImage() to paint your image in the background.
Of course, you may load your image in advance.
good luck
Alfred Wu
Hi,friends:
I am new java programmer. I have the same problem. How can i change the background of a button to an image when I press this button?
Cna anybody tell me where can i find the source code like this?
thank you very much!
I had this problem months ago... and searched this database extensively...
Here is my response which works well..
JBackgroundPanel jbp;
.
jbp = new JBackgroundPanel(Toolkit.getDefaultToolkit().getImage("images/loginbg1.jpg"));
GridBagLayout gridbag = new GridBagLayout();
jbp.setLayout(gridbag);
jbp.add(User); //where these are JTextfields
jbp.add(Pass);
Win.getContentPane().add(jbp); //displayed in window but any container will work
.
.
.
class JBackgroundPanel extends JPanel { Image im;
JBackgroundPanel(Image im) { super(); this.im = im; }
public void paintComponent(Graphics g) { g.drawImage(im,0,0,this); } }
And for futher info check out this ...
http://forum.java.sun.com/[email protected]^[email protected]/0