this.setUndecorated(true);//去掉窗体装饰
  
  窗体没有加这个方法时,拖动的时候会像QQ窗体一样,原始位置不变
  待鼠标释放的时候窗体位置才改变
  加了这个方法就鼠标拖到那,窗体就移到那
  能不能即去掉装饰,移动时还能像原先一样呢?
 

解决方案 »

  1.   

    首先,如果你使用了这个方法this.setUndecorated(true);
    那你的窗体如果没有其他处理,应该是不能拖动的
    如果想你说的还能拖动,
    那估计是添加了mouseListener自己实现的
    原来肯定是鼠标释放时才处理,
    你可以改成在dragged的过程中就处理
      

  2.   


    我加了一个Panel覆盖了窗体,在Panel上放控件,最大最小都是自己写的控件
    其他没问题就是拖动的时候不能像以前那样
    高人给指点哈撒
      

  3.   

    写个例子给你参考一下import java.awt.Color;
    import java.awt.Point;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;import javax.swing.JFrame;public class DragFrame extends JFrame {

    private Point offset = new Point();

    public DragFrame() {
    this.setSize(400, 300);
    this.setLocationRelativeTo(null);
    this.setUndecorated(true);
    this.getContentPane().setBackground(Color.RED);
    this.addMouseListener(new MouseAdapter(){
    public void mousePressed(MouseEvent e) {
    offset.x = e.getXOnScreen();
    offset.y = e.getYOnScreen();
    }
    });
    this.addMouseMotionListener(new MouseMotionAdapter(){
    public void mouseDragged(MouseEvent e) {
    int x = getX() + e.getXOnScreen() - offset.x;
    int y = getY() + e.getYOnScreen() - offset.y;
    setLocation(x, y);
    offset.x = e.getXOnScreen();
    offset.y = e.getYOnScreen();
    }
    });
    this.setVisible(true);
    }

    public static void main(String[] args) {
    new DragFrame();
    }
    }
      

  4.   

    把 设置位置的代码移动到 mouseReleased 方法里就是了
      

  5.   

    是这个意思啊
    改好了,import java.awt.Color;
    import java.awt.Point;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JWindow;import com.sun.awt.AWTUtilities;public class DragFrame extends JFrame {

    private Point offset = new Point();
    private JWindow window = new JWindow();
    private JLabel lab = new JLabel();

    public DragFrame() {
    this.setSize(400, 300);
    this.setLocationRelativeTo(null);
    this.setUndecorated(true);
    this.getContentPane().setBackground(Color.RED);
    window.getContentPane().add(lab);
    lab.setBorder(BorderFactory.createLineBorder(Color.GRAY));
    AWTUtilities.setWindowOpaque(window, false);
    this.addMouseListener(new MouseAdapter(){
    public void mousePressed(MouseEvent e) {
    offset.x = e.getXOnScreen();
    offset.y = e.getYOnScreen();
    window.setBounds(getX(), getY(), getWidth(), getHeight());
    window.setVisible(true);
    }
    public void mouseReleased(MouseEvent e) {
    setLocation(window.getX(), window.getY());
    window.setVisible(false);
    }
    });
    this.addMouseMotionListener(new MouseMotionAdapter(){
    public void mouseDragged(MouseEvent e) {
    int x = window.getX() + e.getXOnScreen() - offset.x;
    int y = window.getY() + e.getYOnScreen() - offset.y;
    window.setLocation(x, y);
    offset.x = e.getXOnScreen();
    offset.y = e.getYOnScreen();
    }
    });
    this.setVisible(true);
    }

    public static void main(String[] args) {
    new DragFrame();
    }
    }
      

  6.   


    谢谢你了啊
    大哥
    我搞半天没搞出来
    哈哈
    终于实现了
    Thank