// runnable can be a func(O o) {} receving the selected item static JList onDoubleClick(final JList list, final O runnable) { swing { list.addMouseListener(new MouseAdapter { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { int idx = list.locationToIndex(evt.getPoint()); O item = list.getModel().getElementAt(idx); list.setSelectedIndex(idx); callF(runnable, item); } } }); } ret list; } // runnable can be a func(O o) {} receving the selected row index static JTable onDoubleClick(final JTable table, final O runnable) { swing { table.addMouseListener(new MouseAdapter { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { int idx = table.rowAtPoint(evt.getPoint()); table.setRowSelectionInterval(idx, idx); callF(runnable, idx); } } }); } ret table; } // other components get the pointer position // only reacts on left button static void onDoubleClick(final JComponent c, final O runnable) { swing { c.addMouseListener(new MouseAdapter { public void mouseClicked(MouseEvent evt) { if (evt.getButton() == 1 && evt.getClickCount() == 2) callF(runnable, evt.getPoint()); } }); } }
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: | 705 / 883 |
Version history: | 2 change(s) |
Referenced in: | [show references] |