1 | // runnable can be a func(O o) {} receving the selected item |
2 | static JList onDoubleClick(final JList list, final O runnable) { |
3 | swing { |
4 | list.addMouseListener(new MouseAdapter { |
5 | public void mouseClicked(MouseEvent evt) { |
6 | if (evt.getClickCount() == 2) { |
7 | int idx = list.locationToIndex(evt.getPoint()); |
8 | O item = list.getModel().getElementAt(idx); |
9 | list.setSelectedIndex(idx); |
10 | callF(runnable, item); |
11 | } |
12 | } |
13 | }); |
14 | } |
15 | ret list; |
16 | } |
17 | |
18 | // runnable can be a func(O o) {} receving the selected row index |
19 | static JTable onDoubleClick(final JTable table, final O runnable) { |
20 | swing { |
21 | table.addMouseListener(new MouseAdapter { |
22 | public void mouseClicked(MouseEvent evt) { |
23 | if (evt.getClickCount() == 2) { |
24 | int idx = table.rowAtPoint(evt.getPoint()); |
25 | table.setRowSelectionInterval(idx, idx); |
26 | callF(runnable, idx); |
27 | } |
28 | } |
29 | }); |
30 | } |
31 | ret table; |
32 | } |
33 | |
34 | // other components get the pointer position |
35 | // only reacts on left button |
36 | static void onDoubleClick(final JComponent c, final O runnable) { |
37 | swing { |
38 | c.addMouseListener(new MouseAdapter { |
39 | public void mouseClicked(MouseEvent evt) { |
40 | if (evt.getButton() == 1 && evt.getClickCount() == 2) |
41 | callF(runnable, evt.getPoint()); |
42 | } |
43 | }); |
44 | } |
45 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003586 |
Snippet name: | onDoubleClick (for JList/JTable/other components) |
Eternal ID of this version: | #1003586/3 |
Text MD5: | 586433fce2521a91c1a832e2b962ed4e |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-05-28 18:25:00 |
Source code size: | 1372 bytes / 45 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 706 / 884 |
Version history: | 2 change(s) |
Referenced in: | [show references] |