Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 20 of 20

Thread: JFrame - ImageIcon not displaying

Threaded View

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JFrame - ImageIcon not displaying

    Hey, I was hoping someone could point out why my image may not be showing. Note I am using eclipse.

    Window.java:

    import javax.swing.*; 
     
    public class Window 
    {
    	private JFrame gameWindow; 
     
    	public Window() 
    	{
    		gameWindow = new JFrame("Tamagotchi!");
    		gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		gameWindow.setBounds(0,0,800,600);
     
    		SplashScreen splashScreen = new SplashScreen(); 
    		gameWindow.add(splashScreen.getContent());
    		gameWindow.setVisible(true);
    	}
     
    	public static void main(String[] args)
    	{
    		new Window();
    	}
     
    }

    SplashScreen.java:

    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
     
    public class SplashScreen
    {
    	private JPanel splashPanel;
    	private JLabel background;
    	private ImageIcon backgroundImage;
     
    	public SplashScreen()
    	{
    		splashPanel = new JPanel();
    		backgroundImage = new ImageIcon("splash_screen.png");
    		background = new JLabel(backgroundImage);
    		splashPanel.add(background);
    		splashPanel.setBounds(0,0,800,600);
    	}
     
    	public JPanel getContent() {
    		return splashPanel;
    	}
    }

    I have used file.exists() and this returns true, and file.length() which returns the correct file size.
    System.out.println(backgroundImage) returns "splash.png" so thats ok.

    Why then is my image not showing?

    Thanks for reading.
    Last edited by mohagan9; April 15th, 2014 at 07:50 AM.


Similar Threads

  1. Update JLabel with new ImageIcon
    By iHank in forum AWT / Java Swing
    Replies: 5
    Last Post: February 6th, 2014, 09:36 AM
  2. Can't load image from folder. ImageIcon
    By kinkita in forum AWT / Java Swing
    Replies: 2
    Last Post: July 19th, 2013, 04:19 PM
  3. How to put in a "new" image in ImageIcon JFrame ?
    By craigjlner in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 29th, 2013, 03:17 PM
  4. Help with ImageIcon
    By nivangerow in forum What's Wrong With My Code?
    Replies: 18
    Last Post: August 30th, 2011, 10:39 AM
  5. displaying multiple jpanels in a jframe
    By tooktook22 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 19th, 2011, 01:46 PM