因为做窗体用的是matisse的插件,所有给出关键性的代码
窗体名jm,按住jlabel1拖动
this.setLocationRelativeTo(null);
jLabel1.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
}
});
jLabel1.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
jm.setLocation(e.getX() + jm.getX() - x, e.getY() + jm.getY()
- y);
}
});