List of usage examples for javax.swing JComponent getInputMap
public final InputMap getInputMap()
InputMap
that is used when the component has focus. From source file:Main.java
/** * Binds an action to a component. Uses the <code>Action.ACTION_COMMAND_KEY</code> and <code>Action.ACCELERATOR_KEY</code> action * properties.//from w w w . ja v a 2s . c o m * * @param component * the component. * @param action * the action to bind. */ public static void bindAction(JComponent component, Action action) { component.getInputMap().put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), action.getValue(Action.ACTION_COMMAND_KEY)); component.getActionMap().put(action.getValue(Action.ACTION_COMMAND_KEY), action); }
From source file:Main.java
public static void bind(JComponent table, Action deleteAction, int key) { KeyStroke delete = KeyStroke.getKeyStroke(key, 0); table.getInputMap().put(KeyStroke.getKeyStroke(key, 0), delete); table.getActionMap().put(table.getInputMap().get(KeyStroke.getKeyStroke(key, 0)), deleteAction); }
From source file:Main.java
/** * Add an action to execute when the validation key (Enter) is pressed. * * @param field The field to validate.//w ww.ja va 2 s . c o m * @param action The action to execute on validate. */ public static void addFieldValidateAction(JComponent field, Action action) { field.getActionMap().put("validate", action); field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "validate"); }
From source file:Main.java
public static void addAction(JComponent component, String kstr, AbstractAction action) { KeyStroke ks = KeyStroke.getKeyStroke(kstr); component.getInputMap().put(ks, ks); component.getActionMap().put(ks, action); }
From source file:Main.java
public static void addAction(JComponent component, String keyStroke, AbstractAction action) { KeyStroke ks = KeyStroke.getKeyStroke(keyStroke); if (ks == null) throw new IllegalArgumentException("invalid key stroke: " + keyStroke); Object key = ks + "-" + System.currentTimeMillis(); component.getActionMap().put(key, action); component.getInputMap().put(ks, key); }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Adds Key navigation bindings to a component. (Is this needed?) * @param comp the component/*from w w w .j av a 2s . co m*/ */ public void addNavBindings(JComponent comp) { InputMap inputMap = comp.getInputMap(); //Ctrl-b to go backward one character KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_B, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); inputMap.put(key, DefaultEditorKit.backwardAction); //Ctrl-f to go forward one character key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); inputMap.put(key, DefaultEditorKit.forwardAction); //Ctrl-p to go up one line key = KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); inputMap.put(key, DefaultEditorKit.upAction); //Ctrl-n to go down one line key = KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); inputMap.put(key, DefaultEditorKit.downAction); }
From source file:com.osparking.attendant.AttListForm.java
/** * Creates new form AttListForm//from w w w .ja va 2 s . co m */ public AttListForm(IMainGUI mainGUI, String loginID, String loginPW, boolean isManager) { // Mark the first row as selected in default this.mainGUI = mainGUI; try { initComponents(); setLocation(0, 0); setIconImages(OSPiconList); // Reset search column combobox items searchCriteriaComboBox.removeAllItems(); searchCriteriaComboBox.addItem(new ConvComboBoxItem(LOGIN_ID_LABEL, LOGIN_ID_LABEL.getContent())); searchCriteriaComboBox.addItem(new ConvComboBoxItem(NAME_LABEL, NAME_LABEL.getContent())); // Make last 8 digits of the user ID visible on the user password label. String id = loginID; if (loginID.length() > 8) { id = ".." + loginID.substring(loginID.length() - 8); } userPWLabel.setText(id + " " + MY_PW_LABEL.getContent()); this.loginID = loginID; this.loginPW = loginPW; this.isManager = isManager; initComponentsUser(); // limit maximun allowed length of user IDa userIDText.setDocument(new JTextFieldLimit(20)); ListSelectionModel model = usersTable.getSelectionModel(); model.addListSelectionListener(new AttendantRowSelectionListener()); setFormMode(FormMode.NormalMode); loadAttendantTable(""); int selectIndex = searchRow(loginID); if (rowHidden(usersTable, selectIndex)) { usersTable.changeSelection(selectIndex, 0, false, false); } else { usersTable.setRowSelectionInterval(selectIndex, selectIndex); } usersTable.requestFocus(); usersTable.getRowSorter().addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(final RowSorterEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (e.getType() == RowSorterEvent.Type.SORTED) { if (usersTable.getSelectedRow() != -1) { usersTable.scrollRectToVisible( usersTable.getCellRect(usersTable.getSelectedRow(), 0, false)); } } } }); } }); } catch (Exception ex) { logParkingException(Level.SEVERE, ex, "(AttListForm Constructor ID: " + loginID + ")"); } JComponent pane = (JComponent) this.getContentPane(); pane.getInputMap().put(null, MUTEX_DEBUG_SEQ_VALUE); addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { searchText.requestFocus(); } }); attachEnterHandler(searchText); adminAuth2CheckBox.setSelected(isManager); KeyStroke controlF = KeyStroke.getKeyStroke("control F"); JRootPane rootPane = getRootPane(); rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(controlF, "myAction"); rootPane.getActionMap().put("myAction", new Ctrl_F_Action(searchText)); }
From source file:com.osparking.attendant.AttListForm.java
private void attachEnterHandler(JComponent compo) { Action handleEnter = new AbstractAction() { public void actionPerformed(ActionEvent e) { searchButtonActionPerformed(null); }/*from w w w . j ava 2 s .c o m*/ }; compo.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "handleEnter"); compo.getActionMap().put("handleEnter", handleEnter); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void bindKeyFocused(JComponent component, String key, String actionKey, Action action) { component.getInputMap().put(KeyStroke.getKeyStroke(key), actionKey); component.getActionMap().put(actionKey, action); }
From source file:storybook.toolkit.swing.SwingUtil.java
public static void addCtrlEnterAction(JComponent comp, AbstractAction action) { InputMap inputMap = comp.getInputMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), action); }