aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to put image as background image in JPanel. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to put image as background image in JPanel." Watch "How to put image as background image in JPanel." New topic
Author

How to put image as background image in JPanel.

Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
Hi Friends,
I would like to place an image as background image in JPanel or paint the background of a JPanel with GradientPaint . My JPanel is acting as input form. Could anybody help me out in this matter.Please this is urgent.
Thanks in adv.
Sonu
[ August 21, 2002: Message edited by: Sonu Ghosh ]
Mahesh swami
Greenhorn

Joined: Aug 13, 2002
Posts: 26
See u can override paintComponent(Graphics g) method of JPanel and in it u can use g.drawImage() method.To show gradientPaint, u can call g.setPaint(GradientPaint) and g.fillRect(x,y,width,height).This should work.TO show the image u can also add a JLAbel of JPanel;s size and set Icon for the JLabel as the Image u want to display
Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
Thanks for the suggestion.I managed to do that.
This is what I have done

Sonu
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to put image as background image in JPanel.