查一查Label的函数应该有相关方法

解决方案 »

  1.   

    1:生成两个label:label1,label2;
       调用label1.setOpaque(true);label2.setOpaque(true);
    2: 生成一个JLayeredPane: layeredPane
    3:调用layeredPane.add(label1,0);
           layeredPane.add(label2,1);
    4: 在程序中添加一个按钮,用来切换label的层次,在事件处理函数中:
           调用layeredPane.setLayer(Component,layer,position)
      

  2.   

    liaomingxue,你好这是我的原程序帮我看看,我在拖动LABEL1的时候,出了区域就被盖住了怎么办??
    package untitled31;
    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 unascribed
     * @version 1.0
     */public class Frame1 extends JFrame {
      private JPanel contentPane;
      private XYLayout xYLayout1 = new XYLayout();
      private JTabbedPane jTabbedPane1 = new JTabbedPane();
      private JLabel jLabel1 = new JLabel();
      private JLabel jLabel2 = new JLabel();
      JTabbedPane jTbPnBase = new JTabbedPane();
      //Construct the frame
      public Frame1() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception  {
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(xYLayout1);
        this.setSize(new Dimension(506, 369));
        this.setTitle("Frame Title");
        jLabel1.setText("jLabel1");
        jLabel2.setText("jLabel2");
        contentPane.add(jTabbedPane1, new XYConstraints(14, 123, 234, 229));
        contentPane.add(jLabel1,  new XYConstraints(138, 58, 86, 25));
        contentPane.add(jLabel2,  new XYConstraints(288, 30, 167, 242));
        jLabel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
                 public void mouseDragged(MouseEvent e) {
                   jLabel1_mouseDragged(e);
                 }
        });
        JPanel jPnlTask = new JPanel(new FlowLayout());
        jTabbedPane1.add("Task", jPnlTask);
        jPnlTask.add(jLabel1);
      }
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }
      void jLabel1_mouseDragged(MouseEvent e){
        jLabel1.setCursor(new Cursor(Cursor.HAND_CURSOR));
        jLabel1.setLocation(jLabel1.getX() +e.getX(),jLabel1.getY() +e.getY());
        //contentPane.add(jLabel1);
        //contentPane.add(jTabbedPane1);
        //contentPane.add(jLabel2);  }
    }
      

  3.   

    你将label1放到一个容器(这里是jPnlTask)中后,是不能移动到
    这个容器之外的。既然label1是移动的,不妨退一步。我这里有个演示程序
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;public class Frame1 extends JFrame
    {
      private JTabbedPane jTabbedPane1 = new JTabbedPane();
      private JLabel jLabel1 = new JLabel();
      private JLabel jLabel2 = new JLabel();
      private XYLayout xYLayout1 = new XYLayout();  public Frame1()
      {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {jbInit(); }
        catch(Exception e) {e.printStackTrace();}
      }
      private void jbInit() throws Exception
      {
        JLayeredPane layerPane=new JLayeredPane();
        layerPane.setLayout(xYLayout1);
        this.setSize(new Dimension(506, 369));
        this.setTitle("Frame Title");    jLabel1.setOpaque(true);
        jLabel1.setText("jLabel1");
        jLabel2.setOpaque(true);
        jLabel2.setText("jLabel2");
        jLabel2.setBackground(Color.blue);
        jLabel1.setBackground(Color.cyan);
        layerPane.add(jTabbedPane1, new XYConstraints(14, 123, 234, 229),1);
        layerPane.add(jLabel2,new XYConstraints(288, 30, 167, 242),2);
        layerPane.add(jLabel1,new XYConstraints(108, 158, 86, 25),0);
        jLabel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
        {
                 public void mouseDragged(MouseEvent e) {jLabel1_mouseDragged(e);}
        });
        layerPane.setPreferredSize(new Dimension(300, 310));
        JPanel p=new JPanel();
        jTabbedPane1.add("Task",p);
        this.getContentPane().add(layerPane);
      }
      protected void processWindowEvent(WindowEvent e)
      {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0);
      }
      void jLabel1_mouseDragged(MouseEvent e)
      {
        jLabel1.setCursor(new Cursor(Cursor.HAND_CURSOR));
        jLabel1.setLocation(jLabel1.getX() +e.getX(),jLabel1.getY() +e.getY());
      }
      public static void main(String [] args)
      {
        Frame1 f=new Frame1();
        f.show();
      }
    }