Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Jframe image as background over content

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am trying to get an animated gif as a background of my JFrame, what I do is:


My frame has a drawPanel where I paint some things, the JPanel has it's own class where I call paintComponent() to draw everything, the constructor of my frame is something like this

The result is the image in front of everything, what I drew on panel is under image and I expect it to be over the image since the gif is a background but it's not behaving like it. Do you know what i am doing wrong? Besides the image is not 400x600, it's a bit smaller so it does not cover full frame, I'd need to scale but that's another thing what really matters is to get it as background and not over my panel.

Greetings!
 
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a link to Rob Camick's example entitled Background Panel. This should at least get you started.
 
Eduardo Rod
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok Thank you I am checking it. I was trying to use a a JLayeredPane without success.

and on setImage() I got

but it does not work, the panel does not show. I will test the BackgroundPanel and post anything if works.

edit: The BackgroundPanel does a very nice job however my gif is still on top, each time I press a key the content of the drawPanel shows up but it's like a small flash, what I only see is the gif moving but the other stuff is not on top. This is my modified code which still does not work, any help?

 
Eduardo Rod
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I never realized I was painting a background at the drawPanel and that it was blocking the BackgroundPanel. This code now works,I can add my drawPanel to the BackgroundPanel as follow:

 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic