• 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

Image

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell me how to add a .gif image in a Frame ?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a couple of ways. One way is to create an ImageIcon of the gif and then apply that to a component like a JLabel or JButton.
Another way to to set a gif as your background Image.
After you create a new ImageIcon of your gif and then you add that to a JLabel the size of your JFrame but to make sure everything gets put on top of that image, you have to add this line.
myJFrame.add(myImageIcon, new Integer(Integer.MIN_VALUE))
 
Kaby Khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cool thanks ione thing though , I am using Frame not JFrame ... will it work like that too?
well I ll try thank alot though.
 
Kaby Khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a Frame would that make a difference?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes... using AWT makes a difference... No ImageIcon class in AWT...

To display an Image in a frame you either have to override the paint() method of the Frame and draw your image there, or use another component ( like an extended Panel or Canvas ) to draw your image on, and then add that component to the Frame. I prefer the latter... Here's a class called ImagePanel that I just had lying around...



And here's a class that illustrates how to use it...



HTH,
-Nate
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nate is the man. If I were you, however, I would look at what I was programming and my design, and (depending on how far into it you are) evaluate the reasons you chose to use the AWT instead of SWING, for your Frame if not your whole App.
The AWT still serves it's purpose. I just really dig SWING alot.
Just my two cents.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic