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.

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.