Results 1 to 8 of 8

Thread: [RESOLVED] Background Image JLabel

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    54

    Resolved [RESOLVED] Background Image JLabel

    Hello
    I want to create a JPanel with a background image, and on that background image I want to arrange my buttons and text feilds etc in a border layout. Is this possibe? Having real trouble accomplishing this. Any assistence will be appreciated. I am using Java 2 at the moment. Thanks in advance

    Code:
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.BorderLayout;
     
    public class GUI2 extends JFrame
    {
    	ImageIcon icon;
    	Image image;
     
    	public GUI2()
    	{
    		icon = new ImageIcon("background.jpg");
    		JPanel panel = new JPanel()
    		{			
    			protected void paintComponent(Graphics g)
    			{
    				//  Dispaly image at full size
    				g.drawImage(icon.getImage(), 0, 0, null); 	
    				super.paintComponent(g);
    			}
    		};
    		panel.setOpaque( false );
    		panel.setPreferredSize( new Dimension(400, 400) );	
    		getContentPane().add( panel ); 
     		panel.setLayout(new BorderLayout()); 		
     		JPanel southPanel = new JPanel();
     		JButton button = new JButton( "Hello" );
     		southPanel.setOpaque(true);
     		button.setOpaque(true);
     		southPanel.add(button); 		
     		add(southPanel, BorderLayout.NORTH); 	
     	//	southPanel.add(button);
     	//	southPanel.add(b);		
    	} 
    	public static void main(String [] args)
    	{
    		GUI2 frame = new GUI2();
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(450,  250);
    		frame.setLocationRelativeTo( null );
    		frame.setVisible(true);
    	}
    }
    Last edited by 01010011; Nov 15th, 2008 at 08:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width