Libraryless. Click here for Pure Java version (5120L/28K).
1 | sclass WindowDragger extends MouseAdapter {
|
2 | MouseEvent mouseDownEvent; |
3 | JComponent src; |
4 | Pt rel; |
5 | Window window; |
6 | |
7 | *(MouseEvent *mouseDownEvent) {
|
8 | if (mouseDownEvent == null) ret; |
9 | src = optCast JComponent(mouseDownEvent.getComponent()); |
10 | if (src == null) ret; |
11 | window = getWindow(src); |
12 | if (window == null) ret; |
13 | |
14 | rel = pt( |
15 | mouseDownEvent.getXOnScreen()-window.getX(), |
16 | mouseDownEvent.getYOnScreen()-window.getY()); |
17 | |
18 | addMouseAndMotionListener(src, this); |
19 | } |
20 | |
21 | public void mouseDragged(MouseEvent e) {
|
22 | updatePosition(e); |
23 | } |
24 | |
25 | public void mouseReleased(MouseEvent e) {
|
26 | if (e.getButton() != mouseDownEvent.getButton()) ret; |
27 | updatePosition(e); |
28 | removeMouseAdapter(src, this); |
29 | dragDone(); |
30 | } |
31 | |
32 | void updatePosition(MouseEvent e) {
|
33 | window.setLocation( |
34 | e.getXOnScreen()-rel.x, |
35 | e.getYOnScreen()-rel.y); |
36 | } |
37 | |
38 | void dragDone {}
|
39 | } |
Began life as a copy of #1018716
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1033463 |
| Snippet name: | WindowDragger - drag da window around [for undecorated JFrames, OK] |
| Eternal ID of this version: | #1033463/13 |
| Text MD5: | 08408e3b6ee184ca5d010e6f36eba2d9 |
| Transpilation MD5: | a16fe23f483afa00480aa94d7ac778c4 |
| Author: | stefan |
| Category: | javax / gui |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-10-29 00:51:22 |
| Source code size: | 957 bytes / 39 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 437 / 629 |
| Version history: | 12 change(s) |
| Referenced in: | [show references] |