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


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

JavaX fragment (include)

static JTable sexyTableWithoutDrag() {
  final JTable table = tableWithToolTips();

  tablePopupMenu(table, voidfunc(JPopupMenu menu, final int row) {
    final S item = first(getTableLine(table, row));
    MouseEvent e = tablePopupMenu_mouseEvent!;
    final int col = table.columnAtPoint(e.getPoint());
    final O value = table.getModel().getValueAt(row, col);
    //print("Cell type: " + getClassName(value));

    if (value instanceof ImageIcon) {
      addMenuItem(menu, "Copy image to clipboard", r {
        copyImageToClipboard(((ImageIcon) value).getImage());
    } else {
      final S text = str(value);
      addMenuItem(menu, "Copy text to clipboard", r {
        print("Copied text to clipboard: " + quote(text));
    addMenuItem(menu, "Set row height...", r {
      final JTextField tf = jTextField(table.getRowHeight());
      showTitledForm("Set row height",
        "Pixels", tf, r {
  // Disable Ctrl+PageUp and Ctrl+PageDown
  table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
  //table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, InputEvent.CTRL_MASK), "none");
    KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK),
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
  ((InputMap) UIManager.get("Table.ancestorInputMap")).put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
  ret table;

Author comment

Began life as a copy of #1004471

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

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/1
Text MD5: 7dd92f2041294ca153178700398501d8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-16 15:25:59
Source code size: 2262 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 25 / 35
Referenced in: [show]