aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Why can't I get this icon to show up in amy application?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why can Watch "Why can New topic
Author

Why can't I get this icon to show up in amy application??

Hemal Mehta
Ranch Hand

Joined: Nov 16, 2000
Posts: 101
See the following project. The inco WINDOWLOGO.GIF is not coming up in the pllication when it is run. Can anyone shed some light?
/**
* Title: Swing project 1

* Description: Swing project 1

* Copyright: Copyright (c) Hemal Mehta

* Company: Sabre

* @author Hemal Mehta
* @version 1.0
*/
package swing1;
//Importing Swing packages
import javax.swing.*;
import javax.swing.event.*;
//Importing AWT packages
import java.awt.*;
import java.awt.event.*;
public class JLabelExample extends JPanel
{
//Create a JLabel text label
JLabel labelText=new JLabel("This is a text JLabel",JLabel.CENTER);
//Create an image icon
ImageIcon icon=new ImageIcon("WINLOGO.gif");
//Create a label with icon
JLabel labelIcon=new JLabel(icon);
//Create a label with both an icon and text
JLabel labelBoth=new JLabel("This is my Icon Jlabel",icon,JLabel.CENTER);
//constructor
public JLabelExample()
{
//Set the layout of our panel
setLayout(new GridLayout(3,1));
//Change teh color of the text label
labelText.setForeground(Color.red);
//Add a tooltip to the text label
//labelText.setToolTipText("This is a Jlabel!");
//Add all the labels to the panel
add(labelText);
add(labelIcon);
add(labelBoth);
}
public static void main(String[] args)
{
//Create a JFrame object
JFrame frame=new JFrame("JlabelExample!");
//Create a JFrameexample Object
JLabelExample JLabelExample1 = new JLabelExample();
//Add our JFrame example object to the JFrame
frame.getContentPane().add(JLabelExample1,BorderLayout.CENTER);
//Resize our frame
frame.setSize(300,180);
//Make our JFrame visible
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
I didn't try to compile your code, but when I have seen this sort of behavior it was because Java could not find the .gif (Java doesn't complain about this).
The way it's written, make sure that the .gif is in the same directory where you launch the virtual machine from.
If this doesn't work, let us know.
Hemal Mehta
Ranch Hand

Joined: Nov 16, 2000
Posts: 101
Yeah I tried that I made sure that WINLOGO.gif is in the same directory. It still didn't work, I am kind of frustated. Can anybody provide some clue.
corneilguy
Greenhorn

Joined: Feb 03, 2001
Posts: 12
Maybe the file is named ".gif" and not ".GIF".
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
Dear Hemal,
I compiled your code and it worked fine for me. I used a different .gif and just named it winlogo.gif (this is case insensitive).

Yeah I tried that I made sure that WINLOGO.gif is in the same directory.

Are you SURE that the location of the image is in the same directory as where you launch the VM from? You have this in package swing1, so to get it to work, you would be in the swing1 directory and type java swing1.JLabelExample (the directory directly above swing1 needs to be in your CLASSPATH)
It smells like this is the problem, if it isn't, perhaps the .gif is not valid. Try a .gif that you know will work, like one from the tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/label.html. Then again, maybe Java just doesn't like something called WINLOGO ...
[This message has been edited by Michael Hildner (edited February 04, 2001).]
Hemal Mehta
Ranch Hand

Joined: Nov 16, 2000
Posts: 101
Thanks for the explanation. I will try this and let you know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why can't I get this icon to show up in amy application??