add the codes to the event of mousemoved,and see if the button is pressed,if so,move the label and else do nothing

解决方案 »

  1.   

    void jLabel1_mouseDragged(MouseEvent e) {
         ~~~~~~~改为Frame
        jLabel1.setLocation(e.getPoint()); }
      

  2.   

    ~~~~~~~改为Frame我的意思是 ,,,你用的那个窗体的mouseDragged事件
      

  3.   

    显然错误
    e.getPoint()返回的是相对于JLabel的位置
    而你需要的是相对于JLabel所在的容器的位置
    反复看e.getPoint的值你就知道了.....
      

  4.   

    我确实把装控件的容器panel改成XYLayout(),可是还不行呀!好惨呀!!!
      

  5.   

    呵呵,不是XYLayout,布局应当是null
    如果有布局的话, setLocation函数是不起作用的,布局管理器会根据当前的布局自己确定位置的.
      

  6.   

    还是不行呀!
    我的布局是这样的
    Frame(this)
        contentpane
          borderlayout
             jPanel1
              null
              jLabel1
    能给我一个具体的例子吗?谢谢,这是我的毕业设计,我很想把它做好呀!
      

  7.   

    jlabel好像不能接受鼠标信息. .两个解决办法:
    1.在jalbel同样的位置上放一个隐形的jbutton<应该是把jbutton和jlabel捆绑在一起>
    2.或者对整个jlabel所在的容器监视鼠标事件,一旦发生鼠标按下,拖动和释放事件时,判断鼠标位置是否在某个jlabel中移动的位置等等, ,具体思路自己想吧.. . .