• Post Reply Bookmark Topic Watch Topic
  • New Topic

Background Image  RSS feed

 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a desktop application and want to include a background image, but I can't find a container type that will hold an image. How can I do this?
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know little about Images; I have seen them on JLabels.

I think you might have a better chance of an answer on the Swing forum.
 
Norm Radder
Ranch Foreman
Posts: 2233
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All components have a paint(AWT) or paintComponent(Swing) method that you can override to draw an image as background for that component.
If you search for paintComponent( you'll probably find some examples.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen that, but I was hoping to use a jpg or png image as the background (complex company logo).
 
Norm Radder
Ranch Foreman
Posts: 2233
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use drawImage()
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Lipay:
I am writing a desktop application and want to include a background image, but I can't find a container type that will hold an image. How can I do this?


You can use a JLayered pane. Add your component to a layer far behind your normal components. You'll have to call setOpaque(false) on all the components that draw on top of the background image in order to see the background.

JFrame has a root pane which is already a JLayered pane, so you can just add your component to that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!