I am making a custom JFrame
. I already have this layout, and it works completely fine:
The frame is undecorated, but I want to be able to move it around. I want my custom panel to be the moving grip for this, so what I did was add a MouseMotionListener
to it. The mouseDragged function looks like this:
@Override
public void mouseDragged(MouseEvent e) {
parent.setBounds(e.getX(), e.getY(), parent.getWidth(), parent.getHeight());
}
The parent
field is set in the constructor and is final.
When I try to drag the frame with the panel, it works, but not quite right. The frame constantly flickers between two positions on the screen. I am able to move the frame, but it looks horrible. When I don't drag the frame, it doesn't flicker. The two positions are relative to each other, so if you move the frame, the other one moves along (but doesn't stay at the same distance from the other). Another problem is that the frame doesn't move well with the mouse. So, if you move the frame like 100 pixels in the x direction, the frame moves less pixels in the same direction.
How can you make a moving grip for a JFrame without this happening (and what is actually causing it to do this)?
If more code is required, just tell me.