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 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, 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/2
Text MD5: c54624c22e29895d4263680262fc98be
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-13 16:30:37
Source code size: 2262 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 118 / 125
Version history: 1 change(s)
Referenced in: [show]