JLabels and gifs
"Locascio, Jim" <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.user-interface |
|---|---|
| Message-ID | <4712A45C0680F445A48DEE8E91F9F7D6038FAC93@LHEXCHANGE.hs.district128.org> |
Hello,
I am building a java app which includes JLabels with text and a gif file as the icon. The text for the JLabel always displays. However, the gif images only display when I create the ImageIcon with the full directory path to the gif files. If I try to use a relative path the gif files are not found. I have tried placing the gif files in my classes directory and executing
blankIcon = new ImageIcon("e.gif");
but the file is not found. I have tried numerous other relative paths, none work.
The relevant code is as follows:
******************************************
//Class vars
private final String blankCard = "e.gif";
private ImageIcon blankIcon;
//the different directory options I have tried. Only the full
//path works.
// private final String directory = "C:\\Documents ...\\"
private final String directory = "cards\\";
//private final String directory = "";
//In my Frame code
blankIcon = new ImageIcon(directory + blankCard);
blankLabel = new JLabel("Blank Card Text", blankIcon,JLabel.CENTER);
//Then add the blankLabel to a JPanel.
The text displays, but the icon image does not.
Any suggestions would be greatly appreciated.
Thank you,
Jim Locascio
Math Teacher
Vernon Hills High School
[email protected]