Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to put image as background image in JPanel.

 
Sandeep Ghosh
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion.I managed to do that.
This is what I have done

Sonu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic