• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Background image

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like using a border to draw the image. That way, you don't have to subclass:
 
reply
    Bookmark Topic Watch Topic
  • New Topic