拖吗,你加事件响应,不停设置setLocation(e.getx(),e.gety()),
通过事件改变文本框的位置,一点建议,

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Test extends JFrame{
    JButton b1;
    //JButton b2;
    //JButton b3;
    private int offsetX;
    private int offsetY; public Test(){
    Container contentPane = getContentPane();
            contentPane.setLayout(null);        b1 = new JButton("one");
            contentPane.add(b1);
            Insets insets = contentPane.getInsets();
            b1.setBounds(25 + insets.left, 5 + insets.top, 75, 20);
            
            b1.addMouseListener(
             new MouseAdapter(){
             public void mousePressed(MouseEvent e){
              offsetX=e.getX();
             offsetY=e.getY();
             }
            
             }
            );
            
            b1.addMouseMotionListener(
             new MouseMotionAdapter(){
            
             public void mouseDragged(MouseEvent e){
             b1.move(e.getX()+(int)b1.getLocation().getX()-offsetX,
        e.getY()+(int)b1.getLocation().getY()-offsetY);
            
             }
             }
            );
    }

    public static void main(String[] args){
    Test t=new Test();
    t.setSize(200,200);
    t.setVisible(true);
    }
    }