Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iamabs2001/18790a2770c62983994020ffa6d797f5 to your computer and use it in GitHub Desktop.
Save iamabs2001/18790a2770c62983994020ffa6d797f5 to your computer and use it in GitHub Desktop.
Java Swing Moving Undecorated jFrame
// create global variable
int xx=0;
int yy=0;
// add mouse presesd event listner on the component you want to make dragger
private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {
xx=evt.getX();
yy=evt.getY();
}
// add mouse Dragged event listner on the component you want to make dragger
private void jPanel1MouseDragged(java.awt.event.MouseEvent evt) {
int x=evt.getXOnScreen();
int y=evt.getYOnScreen();
this.setLocation(x-xx, y-yy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment