• 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

ImageIcon

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me. I am trying to add ImageIcons to an application but they are not showing up. I have the gifs in the folder with the class files and it's compiling ok
thanks
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this :
ImageIcon icon = new ImageIcon("images/image.gif");
post your programm here if it wont work.
 
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
"Trung" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
John A Clark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my code. The thing is the gifs showed up on my college computer but they won't work at home. Everything else works fine. The gif files are where they're supposed to be but they don't show.
// set up the ToolBar
tools = new JToolBar();
tools.setLayout(new GridLayout(0,5));
bNew = new JButton("New",
new ImageIcon("new24.gif"));
bNew.setMnemonic('n');
bNew.setBorder(BLACK_BLUE);
bNew.addActionListener(this);
bAdd = new JButton("Add",
new ImageIcon("add24.gif"));
bAdd.setMnemonic('a');
bAdd.setBorder(BLACK_BLUE);
bAdd.addActionListener(this);
bRetrieve = new JButton("Retrieve",
new ImageIcon("find24.gif"));
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once the icon is loaded, you can paint it on a component using ImageIcon's paintIcon method:

You might also want to read up on Sun's Icon tutorial http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html.
 
John A Clark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks I have it working know
cheers
 
reply
    Bookmark Topic Watch Topic
  • New Topic