• Post Reply Bookmark Topic Watch Topic
  • New Topic

Background image  RSS feed

 
Simon Ruddles
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to set the background of a JFrame using a png or jpg file that contains a graphics image, rather than just setting the background colour. I've tried creating a panel, painting the image on the panel and setting it as the frames contentpane but this disturbs the layout when positioned other components on the pane.

Any suggestions would be welcome - I'm sure there must be something obvious that I'm missing (been away from Java for 2 years, heaven forbid).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> setting it as the frames contentpane but this disturbs the layout when
> positioned other components on the pane.

are you doing it in this order

new ImagePanel()://this extends JPanel and paintComponent() draws the image
set imagePanel to BorderLayout//or whatever you had for the frame
add imagePanel to frame
add components to imagePanel//not the frame
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like using a border to draw the image. That way, you don't have to subclass:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!