This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Picture not appearing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Picture not appearing" Watch "Picture not appearing" New topic

Picture not appearing

Ola gharably

Joined: Jul 01, 2003
Posts: 10
Hi all,
Would anybody please tell me what might be wrong with the following lines of code:
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame{
private String name = "image.gif";
private Icon icon = new ImageIcon(name);
private JLabel label;
public Test(){
Container c = getContentPane();
c.setLayout( new FlowLayout() );
label = new JLabel(icon);
public static void main (String args[]) {
Test t = new Test(); t.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE);
NOTE: the image is in the same directory of the java and class files.
This code should just show my picture, right?? then what might be wrong ??
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
Ar yes
Ola gharably
Please try to change your code to the following
private ImageIcon icon;
label.setIcon(icon=new ImageIcon("image.gif"));
Hope to solve your problem

Francis Siu
Ola gharably

Joined: Jul 01, 2003
Posts: 10
Thank you alot Siu, i've tried your suggestion but unfortunatly it didn't solve my problem :roll:
I'm still with my problem
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Nope... it should work just the way you have it. Try and load a different image. It may be a problem with the GIF.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
I'm still with my problem
Get damage!!I do not know why it does not work~~~~
please try to delete
c.setLayout( new FlowLayout() );
change to
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Picture not appearing
Similar Threads
running gifs
I can't load a file with getResource
Selecting applications using Icons in Swing
Picture Woes
How to checked CheckBox in JTree only when user click on CheckBox?