Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ImageIcon  RSS feed

 
John A Clark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Trung Tran
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this :
ImageIcon icon = new ImageIcon("images/image.gif");
post your programm here if it wont work.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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"));
 
Don Gardner
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks I have it working know
cheers
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!