Moving undecorated window by clicking on JPanel

前端 未结 6 804
鱼传尺愫
鱼传尺愫 2021-02-08 15:43

Is there a possibility to move window by clicking on one of the panels in the window when that window is undecorated?

I have a main panel with matte border 40 pixels siz

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-08 16:34

    Yes, it is very possible. You need a MouseListener to listen on mouse events. you start moving on mousedown and stop moving on mouseup. Then you simply translate the window position by the same amount the mouse translates during that phase (calculate the delta bewteen old mouse position and new mouse position and add that to the frames position). You should be able to do this with a mouse listener fairly easily.

提交回复
热议问题