My image wont show up in its layer

Hi, my problem is that when i add my image to my layeredpane, and then too my frame, the image doesnt show up! but the layerdpane border does...so i need to know how to change my code in order for my picture to appear THANKS!

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

import java.io.*;

import java.io.File;

import java.io.FileInputStream;

import javax.swing.border.*;

import javax.swing.JRootPane.*;

import javax.accessibility.*;

public class frames extends JPanel

{

JLayeredPane layeredPane;

JLabel bg;

JFrame frame;

public void frames()

{

JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.

frame = new JFrame("Knobellen");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.

JComponent newContentPane = new Background();

newContentPane.setOpaque(true); //content panes must be opaque

frame.setContentPane(newContentPane);

//Display the window.

frame.pack();

frame.setVisible(true);

}

public class Background extends JPanel

{

Background()

{

ImageIcon image = createImageIcon("bg.gif");

//layeredpane creating

setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

layeredPane = new JLayeredPane();

layeredPane.setPreferredSize(new Dimension(864, 648));

layeredPane.setBorder(BorderFactory.createTitledBorder("KnoBALLER PWNED"));

bg = new JLabel(image);

//add image to layerdpane

layeredPane.add(bg, new Integer(2));

add(Box.createRigidArea(new Dimension(0, 10)));

add(layeredPane);

}

}

protected static ImageIcon createImageIcon(String path) {

//Checks to see if path is correct

java.net.URL imgURL = Background.class.getResource(path);

if (imgURL != null) {

return new ImageIcon(imgURL);

} else {

System.err.println("Couldn't find file: " + path);

return null;

}

}

}

[2129 byte] By [Terry_Wrighta] at [2007-10-2 18:48:09]
# 1

Hello,

I am right now working with JLayeredPane. After some initial troubles now everyting work fine.

I have tried to start your program by adding

public static void main(String[] s){

new frames();

}

but it doesn't start.

Could you tell me how you start it?

Then I think I will be able to tell you how to work with the layeredPane.

Anyway I don't understand why you need a JPanel. You can work directly with the lyeredPane without any need of intermediate jpanels: frame.setLayeredPane(layeredPane);

Eduado.

Eduardo_Cobiana at 2007-7-13 20:10:50 > top of Java-index,Desktop,Core GUI APIs...