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

53
LINES

< > BotCompany Repo | #1001788 - onEnter (on JTextField, JButton, JList, JComboBox, JTable, JTextArea) - also selects all on JTextField

JavaX fragment (include)

static JTextField onEnter(final JTextField tf, final O action) {
  if (action == null || tf == null) ret tf;
  tf.addActionListener(actionListener {
    tf.selectAll();
    callF(action);
  });
  ret tf;
}

static JButton onEnter(JButton btn, final O action) {
  if (action == null || btn == null) ret btn;
  btn.addActionListener(actionListener(action));
  ret btn;
}

static JList onEnter(JList list, O action) {
  list.addKeyListener(enterKeyListener(rCallOnSelectedListItem(list, action)));
  ret list;
}

static JComboBox onEnter(final JComboBox cb, fO action) {
  swing {
    if (cb.isEditable()) {
      JTextField text = (JTextField) cb.getEditor().getEditorComponent();
      onEnter(text, action);
    } else {
      cb.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter");
      cb.getActionMap().put("enter", abstractAction("", r { cb.hidePopup(); callF(action); }));
    }
  }
  ret cb;
}

static JTable onEnter(final JTable table, fO action) {  
  table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
    
  table.getActionMap().put("Enter", new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
      callF(action, table.getSelectedRow());
    }
  });
  ret table;
}

/*static JTextArea onEnter(final JTextArea ta, fO action) {
  addKeyListener(ta, enterKeyListener(action));
  ret ta;
}*/

static JTextField onEnter(O action, JTextField tf) {
  ret onEnter(tf, action);
}

download  show line numbers  debug dex   

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

No comments. add comment

Snippet ID: #1001788
Snippet name: onEnter (on JTextField, JButton, JList, JComboBox, JTable, JTextArea) - also selects all on JTextField
Eternal ID of this version: #1001788/27
Text MD5: 6222fc07f38e525c62500b3ab3acd950
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-24 04:57:26
Source code size: 1537 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 506 / 1142
Version history: 26 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1001788 & http://1001788.tinybrain.de