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

58
LINES

< > BotCompany Repo | #1009201 // sexyTableWithoutDrag - JTable with latest fancy stuff, but without drag-enable (bad for double clicks)

JavaX fragment (include)

1  
static JTable sexyTableWithoutDrag() {
2  
  final JTable table = tableWithToolTips();
3  
4  
  tablePopupMenu(table, sexyTableWithoutDrag_popupMenuMaker(table));
5  
  
6  
  // Disable Ctrl+PageUp and Ctrl+PageDown
7  
  
8  
  table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
9  
  //table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, InputEvent.CTRL_MASK), "none");
10  
  /*table.registerKeyboardAction(
11  
    null,
12  
    KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK),
13  
    JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
14  
  );*/
15  
  table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
16  
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
17  
  table.getInputMap(JComponent.WHEN_FOCUSED)
18  
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
19  
  table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
20  
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
21  
  table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
22  
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
23  
  ((InputMap) UIManager.get("Table.ancestorInputMap")).put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
24  
    
25  
  ret table;
26  
}
27  
28  
static VF2<JPopupMenu, Int> sexyTableWithoutDrag_popupMenuMaker(JTable t) {
29  
  final WeakReference<JTable> ref = weakRef(t);
30  
  ret voidfunc(JPopupMenu menu, int row) {
31  
    final JTable table = ref!;
32  
    final S item = first(getTableLine(table, row));
33  
    MouseEvent e = tablePopupMenu_mouseEvent!;
34  
    final int col = table.columnAtPoint(e.getPoint());
35  
    final O value = table.getModel().getValueAt(row, col);
36  
    //print("Cell type: " + getClassName(value));
37  
38  
    if (value instanceof ImageIcon) {
39  
      addMenuItem(menu, "Copy image to clipboard", r {
40  
        copyImageToClipboard(((ImageIcon) value).getImage());
41  
      });
42  
    } else {
43  
      final S text = str(value);
44  
      addMenuItem(menu, "Copy text to clipboard", r {
45  
        copyTextToClipboard(text);
46  
        print("Copied text to clipboard: " + quote(text));
47  
      });
48  
    }
49  
    
50  
    addMenuItem(menu, "Set row height...", r {
51  
      final JTextField tf = jTextField(table.getRowHeight());
52  
      showTitledForm("Set row height",
53  
        "Pixels", tf, r {
54  
          table.setRowHeight(parseInt(trim(tf.getText())))
55  
        });
56  
    });
57  
  };
58  
}

Author comment

Began life as a copy of #1004471

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009201
Snippet name: sexyTableWithoutDrag - JTable with latest fancy stuff, but without drag-enable (bad for double clicks)
Eternal ID of this version: #1009201/7
Text MD5: f9890adb2b728d2cb1bbc9244827be87
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-07 17:08:10
Source code size: 2470 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 552 / 540
Version history: 6 change(s)
Referenced in: [show references]