static <A extends JComponent> A draggableFloatingComponent(final A a) {
final new Var<Pt> pt; // where in the component mouse was clicked
addMouseListener(a, new MouseAdapter {
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1)
pt.set(pt(e.getX(), e.getY()));
}
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
//a.setLocation(e.getX()+pt->x, e.getY()+pt->y);
pt.set(null);
}
}
});
addMouseMotionListener(a, new MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
Point scr = e.getLocationOnScreen();
Point p = a.getParent().getLocationOnScreen();
a.setLocation(scr.x-pt->x-p.x, scr.y-pt->y-p.y);
}
});
ret a;
}download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1020259 |
| Snippet name: | draggableFloatingComponent |
| Eternal ID of this version: | #1020259/5 |
| Text MD5: | 25973160502bc63747c74615e814df15 |
| Author: | stefan |
| Category: | javax / gui |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-12-11 23:47:02 |
| Source code size: | 825 bytes / 27 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 660 / 686 |
| Version history: | 4 change(s) |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |