Moving undecorated window by clicking on JPanel

前端 未结 6 798
鱼传尺愫
鱼传尺愫 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:30

    int xMoved = (thisX + e.getX()) - (thisX + initialClick.x);
    

    thisX + -thisX = 0

    int xMoved = e.getX()-initialClick.x;
    

    What i'm using.

    public class MouseLiestenerX implements MouseListener,MouseMotionListener{
    
    private theFrame;
    
    public MouseLiestenerX(Frame theFrame){
    this.theFrame = theFrame;
    
    }
    
    private Point startClick;
    
    public void mouseDragged(MouseEvent e) {
        int deltaX = e.getX()-startClick.x;
        int deltaY = e.getY()-startClick.y;
    
        Core.getSp().setLocation(theFrame.getLocation().x+deltaX, theFrame.getLocation().y+deltaY);
    }
    
    public void mousePressed(MouseEvent e) {
        startClick = e.getPoint();
    }
    
    public void mouseMoved(MouseEvent e){
    
    }
    @Override
    public void mouseClicked(MouseEvent e) {
    
    
    }
    @Override
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
    
    }
    @Override
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub
    
    }
    @Override
    public void mouseReleased(MouseEvent e) {
    
    }
    

    }

    and in your Frame constructor

    MouseLiestenerX IMove = new MouseLiestenerX(this);      
    addMouseListener(IMove);
    addMouseMotionListener(IMove);
    

提交回复
热议问题