Current location: Hot Scripts Forums » Programming Languages » Everything Java » Background Images and JLayeredPane

Background Images and JLayeredPane

Reply
  #1 (permalink)  
Old 03-07-06, 12:35 AM
dwoody dwoody is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Background Images and JLayeredPane

I would like to create a background image in my GUI using a JLayeredPane. I have the code shown below and it doesnt display anything at all. Could somebody please help me out.

Code:
import java.awt.*;
import javax.swing.*;
 
public class ImagesExample {
    
		public ImagesExample() {
		
			JFrame frame = new JFrame();
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
			JLayeredPane layers = new JLayeredPane();
			JPanel topPanel = new JPanel();
			
			JLabel bgIm = new JLabel(new ImageIcon("imagepath.jpg"));
			
			layers.add(bgIm, new Integer(1));
			layers.setOpaque(true);
			
			topPanel.add(layers);
			topPanel.setOpaque(true);
			
			JComponent newContentPane = topPanel;
	                newContentPane.setOpaque(true); 
	                frame.setContentPane(newContentPane);
	
	                //Display the window.
	                frame.pack();
	                frame.setVisible(true);			
		}
		
   public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame.setDefaultLookAndFeelDecorated(true);
				new ImagesExample();
			}
		});
    }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-09-06, 06:41 AM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
You never set the size.
__________________
my site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 01:38 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.