javax.swing.JTextField.getInputMap()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中javax.swing.JTextField.getInputMap()方法的一些代码示例,展示了JTextField.getInputMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.getInputMap()方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:getInputMap

JTextField.getInputMap介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

final JList list = new JList(Locale.getAvailableLocales());
final JPopupMenu popup = new JPopupMenu();
popup.add(new JScrollPane(list));
popup.setFocusable(false);
final JTextField field = new JTextField(20);
Action down = new AbstractAction("nextElement") {

  @Override
  public void actionPerformed(ActionEvent e) {
    int next = Math.min(list.getSelectedIndex() + 1,
        list.getModel().getSize() - 1);
    list.setSelectedIndex(next);
    list.ensureIndexIsVisible(next);
  }
};
field.getActionMap().put("nextElement", down);
field.getInputMap().put(
    KeyStroke.getKeyStroke("DOWN"), "nextElement");

代码示例来源:origin: apache/pdfbox

searchField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), closeAction);

代码示例来源:origin: ron190/jsql-injection

textFilter.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");

代码示例来源:origin: stackoverflow.com

int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
JTextField jtf = new JTextField("Test");
jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, MASK), "select-all");
jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, MASK), "copy");
jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_X, MASK), "cut");
jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, MASK), "paste");

代码示例来源:origin: stackoverflow.com

final JTextField jtf = new JTextField("Test");
jtf.getInputMap().put(
  KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK),
  "caret-begin-line");

代码示例来源:origin: triplea-game/triplea

private void setupKeyMap() {
 final InputMap nextMessageKeymap = nextMessage.getInputMap();
 nextMessageKeymap.put(KeyStroke.getKeyStroke('\n'), saveAction);
}

代码示例来源:origin: org.codehaus.mevenide/nb-project

private void hidePopup() {
  field.getInputMap().remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
  field.getInputMap().remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
  if (popup != null) {
    popup.hide();
    popup = null;
  }
}

代码示例来源:origin: stackoverflow.com

final JButton btn = new JButton("Click Me!");
JTextField txt = new JTextField(10);
InputMap inputMap = txt.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = txt.getActionMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), 13);
actionMap.put(13, new AbstractAction()
{
  public void actionPerformed(ActionEvent e)
  {
    btn.doClick();
  }
});

代码示例来源:origin: stackoverflow.com

final JTextField textfield = new JTextField();
Action enterAction = new AbstractAction() {
  @Override
  public void actionPerformed(ActionEvent e) {
    //do something
  }};
 String key = "ENTER";
 KeyStroke keyStroke = KeyStroke.getKeyStroke(key);
 textfield.getInputMap().put(keyStroke, key);
 textfield.getActionMap().put(key, enterAction);

代码示例来源:origin: triplea-game/triplea

private void cleanupKeyMap() {
 final InputMap nextMessageKeymap = nextMessage.getInputMap();
 nextMessageKeymap.remove(KeyStroke.getKeyStroke('\n'));
 nextMessageKeymap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false));
 nextMessageKeymap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false));
}

代码示例来源:origin: stackoverflow.com

public static void main( String[] args ) {
 EventQueue.invokeLater( new Runnable() {
  @Override
  public void run() {
   JTextField textField = new JTextField();
   InputMap inputMap = textField.getInputMap( JComponent.WHEN_FOCUSED );
   KeyStroke[] keyStrokes = inputMap.allKeys();
   for ( int i = 0; i < keyStrokes.length; i++ ) {
    KeyStroke keyStroke = keyStrokes[ i ];
    Object value = inputMap.get( keyStroke );
    System.out.println(keyStroke + "-\"" + value + "\"");
   }
  }
 } );
}

代码示例来源:origin: stackoverflow.com

JTable table = new JTable(myModel);
     JTextField cell = new JTextField();
     final TableCellEditor cellEditor = new DefaultCellEditor(cell);
     table.getColumnModel().getColumn(column).setCellEditor(cellEditor);
     InputMap iMap = cell.getInputMap(JComponent.WHEN_FOCUSED);
     iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),    KeyEvent.getKeyText(KeyEvent.VK_ENTER));
     ActionMap aMap = cell.getActionMap();
     aMap.put(KeyEvent.getKeyText(KeyEvent.VK_ENTER), new AbstractAction() {
       @Override
       public void actionPerformed(ActionEvent e) {
         if(callSomeOperationsIsOk()){
          cellEditor.stopCellEditing();
         }else{
          cellEditor.cancelCellEditing();
         }
       }
     });
 }

代码示例来源:origin: stackoverflow.com

AbstractAction action = new AbstractAction() {
  @Override
  public void actionPerformed(ActionEvent e) {
    if(e.getSource() instanceof JButton){
      JButton button = (JButton) e.getSource();
      button.doClick();                
    } else if(e.getSource() instanceof JComponent){
      JComponent component = (JComponent) e.getSource();
      component.transferFocus();
    }
  }
};

JTextField textField1 = new JTextField();
textField1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "TransferFocus");
textField1.getActionMap().put("TransferFocus", action);

JTextField textField2 = new JTextField();
textField2.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "TransferFocus");
textField2.getActionMap().put("TransferFocus", action);

JButton button1= new JButton();
button1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
button1.getActionMap().put("Enter", action);

代码示例来源:origin: org.codehaus.mevenide/nb-project

private void showPopup() {
  hidePopup();
  if (completionListModel.getSize() == 0) {
    return;
  }
  // figure out where the text field is,
  // and where its bottom left is
  java.awt.Point los = field.getLocationOnScreen();
  int popX = los.x;
  int popY = los.y + field.getHeight();
  popup = PopupFactory.getSharedInstance().getPopup(field, listScroller, popX, popY);
  field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),ACTION_HIDEPOPUP);
  field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),ACTION_FILLIN);
  popup.show();
  if (completionList.getSelectedIndex() != -1) {
    completionList.ensureIndexIsVisible(completionList.getSelectedIndex());
  }
}

代码示例来源:origin: stackoverflow.com

JTextField normal = new JTextField("just a normal field", 10);
 final Action selectAll = normal.getActionMap().get("select-all");
 final Action cut = normal.getActionMap().get("cut-to-clipboard");
 Action combine = new AbstractAction() {
   @Override
   public void actionPerformed(final ActionEvent e) {
     SwingUtilities.invokeLater(new Runnable() {
       @Override
       public void run() {
         selectAll.actionPerformed(e);
         cut.actionPerformed(e);
       }
     });
   }
 };
 normal.getActionMap().put("magic-delete-all", combine);
 normal.getInputMap().put(KeyStroke.getKeyStroke("A"), "magic-delete-all");

代码示例来源:origin: com.numdata/numdata-swing

/**
 * Construct spinner component.
 *
 * @param textField Text field with value to control.
 * @param minValue  Minimum value allowed.
 * @param maxValue  Maximum value allowed.
 */
public Spinner( final JTextField textField, final int minValue, final int maxValue )
{
  super( new GridLayout( 1, 2, 0, 0 ) );
  setBorder( null );
  _textField = textField;
  _minValue = minValue;
  _maxValue = maxValue;
  add( new Button( false ) );
  add( new Button( true ) );
  final InputMap inputMap = textField.getInputMap();
  inputMap.put( KeyStroke.getKeyStroke( '+' ), "incrementValue" );
  inputMap.put( KeyStroke.getKeyStroke( '-' ), "decrementValue" );
  final ActionMap actionMap = textField.getActionMap();
  actionMap.put( "incrementValue", new IncrementAction() );
  actionMap.put( "decrementValue", new DecrementAction() );
}

代码示例来源:origin: pentaho/pentaho-reporting

public PropertyCellEditorWithEllipsis() {
 setLayout( new BorderLayout() );
 this.eventListenerList = new EventListenerList();
 ellipsisButton = new EllipsisButton( "..." );
 ellipsisButton.addActionListener( new ExtendedEditorAction() );
 textField = new JTextField();
 textField.getInputMap().put
  ( Messages.getInstance().getKeyStroke( "PropertyCellEditorWithEllipsis.PopupEditor.Accelerator" ), POPUP_EDITOR );
 textField.getActionMap().put( POPUP_EDITOR, new ExtendedEditorAction() );
 textField.setBorder( BorderFactory.createEmptyBorder() );
 add( textField, BorderLayout.CENTER );
 add( ellipsisButton, BorderLayout.EAST );
 nullable = false;
}

代码示例来源:origin: pentaho/pentaho-reporting

public ArrayCellEditor() {
 setLayout( new BorderLayout() );
 this.eventListenerList = new EventListenerList();
 ellipsisButton = new EllipsisButton( "..." );
 ellipsisButton.setDefaultCapable( false );
 ellipsisButton.addActionListener( new ExtendedEditorAction() );
 textField = new JTextField();
 textField.setDocument( new NonFilteringPlainDocument() );
 textField.getInputMap().put( Messages.getInstance().getKeyStroke
  ( "PropertyCellEditorWithEllipsis.PopupEditor.Accelerator" ), POPUP_EDITOR );
 textField.getActionMap().put( POPUP_EDITOR, new ExtendedEditorAction() );
 textField.setBorder( BorderFactory.createEmptyBorder() );
 textField.setEditable( false );
 add( textField, BorderLayout.CENTER );
 add( ellipsisButton, BorderLayout.EAST );
 nullable = false;
}

代码示例来源:origin: org.jspresso.framework/jspresso-swing-components

/**
 * {@inheritDoc}
 */
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition,
  boolean pressed) {
 if (super.processKeyBinding(ks, e, condition, pressed)) {
  return true;
 }
 Object binding = textField.getInputMap(condition).get(ks);
 if (binding != null && textField.getActionMap().get(binding) != null) {
  textField.dispatchEvent(e);
  return true;
 }
 return false;
}

代码示例来源:origin: org.jspresso/jspresso-swing-components

/**
 * {@inheritDoc}
 */
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition,
  boolean pressed) {
 if (super.processKeyBinding(ks, e, condition, pressed)) {
  return true;
 }
 Object binding = textField.getInputMap(condition).get(ks);
 if (binding != null && textField.getActionMap().get(binding) != null) {
  textField.dispatchEvent(e);
  return true;
 }
 return false;
}

相关文章

JTextField类方法