all way as follows:JLayeredPanel jLP = new JLayeredPanel();
JPanel jP = new JPanel();jLP.add(jP);

解决方案 »

  1.   

    但是我这么做了以后再设置JPanel的背景为红色执行的时候JPanel没有显示出来阿
      

  2.   

    我觉的是应该在JPANEL上再插入象JLABEL,LBUTTON之类。
    JPANEL显示出来能看到吗?
      

  3.   

    应该是可以的阿,JPanel、JScrollPanel都是组件阿是不是他们被遮盖掉了?
      

  4.   

    package test1;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class Frame4
      extends JFrame
    {
      JPanel contentPane;  BorderLayout borderLayout1 = new BorderLayout();  JLayeredPane jLayeredPane1 = new JLayeredPane();
      JPanel jPanel1 = new JPanel();
      JPanel jPanel2 = new JPanel();
      XYLayout xYLayout1 = new XYLayout();  //Construct the frame  public Frame4()
      {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try
        {
          jbInit();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }  //Component initialization
      private void jbInit()
        throws Exception
      {
        contentPane = (JPanel)this.getContentPane();
        contentPane.setBackground(SystemColor.info);
        contentPane.setDebugGraphicsOptions(0);
        contentPane.setLayout(borderLayout1);
        this.setSize(new Dimension(400, 300));
        this.setTitle("Frame Title");
        jLayeredPane1.setBackground(Color.red);
        jLayeredPane1.setOpaque(true);
        jLayeredPane1.setLayout(xYLayout1);
        jPanel1.setBackground(Color.magenta);
        jPanel1.setPreferredSize(new Dimension(150, 100));
        jPanel2.setBackground(Color.green);
        jPanel2.setPreferredSize(new Dimension(100, 150));
        jLayeredPane1.add(jPanel2,  new XYConstraints(5, 5, -1, -1));
        jLayeredPane1.add(jPanel1,  new XYConstraints(5, 160, -1, -1));
        contentPane.add(jLayeredPane1, BorderLayout.CENTER);
        jLayeredPane1.setLayer(jPanel1, 50);
        jLayeredPane1.setLayer(jPanel2, 30);  }  //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e)
      {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING)
        {
          System.exit(0);
        }
      }
    }