Forked from lanarods/gist:a8789af8cfdfd8bd7422cc30f986f65c
Last active
July 31, 2020 09:53
-
-
Save iamabs2001/18790a2770c62983994020ffa6d797f5 to your computer and use it in GitHub Desktop.
Java Swing Moving Undecorated jFrame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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