• 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

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do you put an image into a JPanel??? i can't do ".add(creatureImage, BorderLayout.CENTER);" ��??
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Swing forum.
[ June 07, 2006: Message edited by: marc weber ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the simple way is
panel.add(new JLabel(new ImageIcon("creature.gif")));

and will appear depending on layoutManager

if you want a background image (from the faq)
http://faq.javaranch.com/view?BackgroundImageOnJPanel
 
chris barr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
chris barr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
were do i tell it were to get the picture from ...? i have it saved in my pictures on my computer so how do i tell it to take it from there? do i just include it in name?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the image is in a sub-directory e.g. 'images'
panel.add(new JLabel(new ImageIcon("images/creature.gif")));

or you can specify the full path
panel.add(new JLabel(new ImageIcon("c:/java/images/creature.gif")));

note: if you want to use \, you'll need to use \\
panel.add(new JLabel(new ImageIcon("c:\\java\\images\\creature.gif")));
 
chris barr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does the picture have to be in "gif" format?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> does the picture have to be in "gif" format?

can also be .jpg or .png

I seem to recall other formats being supported in the newer versions of java,
but not sure what they are.
 
chris barr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok cuz the picture that i have that i want to load or bitmaps. and when i add the code to write then they don't appear.


also i am running java 1.5
[ June 12, 2006: Message edited by: chris barr ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can load .bmp images with the ImageIO class and hand the returned
BufferedImage to your ImageIcon constructor. ImageIO support for .bmp
and .wbmp images starts in j2se 1.5

edit for width
[ June 13, 2006: Message edited by: Craig Wood ]
 
chris barr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
------------- <--Explanation


<---- my head



the explanation isn't really above my head i understand it i just don't know how to us said methods...... while i wait for a reply i will mess around and try to figure it out..... thanks
[ June 12, 2006: Message edited by: chris barr ]
 
chris barr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok what i am trying to do now is ...



that doesn't work .. but it compiles and runs and doesn't give an error and i am not catching it or thowing anything.??? let me know if you want more code.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It takes some experimenting, like this:

If you would rather stick with the ImageIcon class for loading, check the
ImageIcon api for the "getImageLoadStatus" which will return information
about loading success.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a quick thank you - this has solved a problem I was struggling with, I'm using:



Works perfectly!
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic