954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Image won't appear in JLabel

Hi. I am trying to display a JFrame containing a JLabel with an image, and I can't get the image to display. The text appears fine.

I've done this before with no problem, so I have no idea what is wrong. I've tried everything I can think of to fix it.

import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main
{
	public static void main( String[] args ) 
	{
		JFrame frame = new JFrame( "VN" );
		JLabel image = new JLabel( "hello", new ImageIcon( "vn1.bmp" ), JLabel.LEFT );
		
		image.setPreferredSize( new Dimension( 720, 460 ) );
		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		
		frame.getContentPane().add( image );
		frame.pack();
		frame.setVisible( true );
	}
}


Thank you.

catpoints
Newbie Poster
3 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 
mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

here

http://download.oracle.com/javase/tutorial/uiswing/components/label.html

or

http://www.java2s.com/Code/Java/Swing-JFC/LabelwithImage.htm

or

google returns tons of examples


I wasn't asking for a tutorial. I already know how to use it.

catpoints
Newbie Poster
3 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

huuuh, sure you are right

ensure I forgot about it, if you would read it, so it would not be here this post

maybe someone...., I'm out of this post

mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

Most likely it's a pathing issue with your image file. Take a look at the How To Use Icons tutorial for some info on locating resources.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Fixed it. Just used a png image instead of a bmp.

catpoints
Newbie Poster
3 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: