Results 1 to 5 of 5
  1. #1
    verd is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Stacking JPanels

    Attempting to stack JPanels to make many layers.
    The problem is the JPanels print out right each other, and will not stack.

    Java Code:
    package core;
    
    import java.awt.*;
    import javax.swing.*;
    
    public class Client extends JApplet{
    	
    	Container contentPane = this.getContentPane();
    	JComponent GraphicsControl = new GraphicsHandler();
    	
    	public void init(){
    		try{
    			javax.swing.SwingUtilities.invokeAndWait(new Runnable(){
    				public void run(){
    					createGUI();
    				}});
    			}catch (Exception e){}
    	}
    	
    	public void start(){
    		
    	}
    	
    	public void stop(){
    		
    	}
    	
    	public void destroy(){
    		
    	}
    	
    	private void createGUI(){
    		this.getContentPane().add(GraphicsControl);
    	}
    }
    Java Code:
    package core;
    
    import java.awt.*;
    import javax.swing.*;
    import interfaces.*;
    import layers.*;
    
    public class GraphicsHandler extends JPanel{
    
    	Main MainInterface = new Main();
    	Status StatusInterface = new Status();
    	
    	public GraphicsHandler(){
    		this.add(MainInterface);
    		this.add(StatusInterface);
    		this.setBackground(Color.black);
    	}
    }
    Java Code:
    package interfaces;
    
    import java.awt.*;
    import javax.swing.*;
    
    public class Main extends JPanel{
    	
    	public Main(){
    		this.setBackground(Color.red);
    		this.setPreferredSize(new Dimension(100,100));
    	}
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Stacking JPanels

    Define stack: do you mean stack in the x/y sense, or stack in the z (3D) sense.
    See A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    And not discussed but pertaining to z stacking:
    OverlayLayout (Java Platform SE 6)

  3. #3
    verd is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: Stacking JPanels

    Z stacking would be better.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,407
    Rep Power
    20

    Default Re: Stacking JPanels

    Read up on JLayeredPane and/or JTabbedPane.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    verd is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: Stacking JPanels

    Got it to work instead of JLayeredPane I put JLayerPane, would of had it done a couple days ago.

Similar Threads

  1. JPanels ?
    By santa in forum New To Java
    Replies: 5
    Last Post: 02-25-2012, 07:10 PM
  2. Replies: 2
    Last Post: 04-26-2011, 02:50 PM
  3. Problems regarding JPanels in JPanels
    By ColtonPhillips in forum AWT / Swing
    Replies: 2
    Last Post: 07-19-2010, 08:33 PM
  4. Window Stacking in Order
    By Turyturbo in forum Advanced Java
    Replies: 3
    Last Post: 03-24-2010, 05:13 PM
  5. HELP with jPanels
    By maverik_vz in forum AWT / Swing
    Replies: 1
    Last Post: 03-12-2009, 11:46 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
  •