How can I customly move JWindow on screen

67 Views Asked by At

I need way for moving JWindow on screen with Drag & Drop. I sort this out with mouse and mouse motion listeners, but it only works partly(it doesn't work if i want to move window upwards). Here is the code.

private boolean drag;
    ...
@Override
public void mouseDragged(MouseEvent e) {
    if(e.getY() < 18){
        p = new Point(e.getXOnScreen(), e.getYOnScreen());
        drag = true;
    }
}

@Override
public void mouseReleased(MouseEvent e) {
    if(drag){
        System.out.println((e.getXOnScreen() + " " + p.x));
        System.out.println((e.getYOnScreen() + " " + p.y));
        this.setLocation(this.getX() + (e.getXOnScreen() - p.x), this.getY() + (e.getYOnScreen() - p.y));
        drag = false;
    }
}
0

There are 0 best solutions below