Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

27
LINES

< > BotCompany Repo | #1020259 // draggableFloatingComponent

JavaX fragment (include)

1  
static <A extends JComponent> A draggableFloatingComponent(final A a) {
2  
  final new Var<Pt> pt; // where in the component mouse was clicked
3  
  
4  
  addMouseListener(a, new MouseAdapter { 
5  
    public void mousePressed(MouseEvent e) {
6  
      if (e.getButton() == MouseEvent.BUTTON1)
7  
        pt.set(pt(e.getX(), e.getY()));
8  
    }
9  
    
10  
    public void mouseReleased(MouseEvent e) {
11  
      if (e.getButton() == MouseEvent.BUTTON1) {
12  
        //a.setLocation(e.getX()+pt->x, e.getY()+pt->y);
13  
        pt.set(null);
14  
      }
15  
    }
16  
  });
17  
  
18  
  addMouseMotionListener(a, new MouseMotionAdapter {
19  
    public void mouseDragged(MouseEvent e) {
20  
      Point scr = e.getLocationOnScreen();
21  
      Point p = a.getParent().getLocationOnScreen();
22  
      a.setLocation(scr.x-pt->x-p.x, scr.y-pt->y-p.y);
23  
    }
24  
  });
25  
  
26  
  ret a;
27  
}

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: 234 / 285
Version history: 4 change(s)
Referenced in: [show references]