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

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

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

JComboBox.getInputMap介绍

暂无

代码示例

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

protected void installKeyboardActions() {
  super.installKeyboardActions();
  //Basic UI won't install an action to open the combo on spacebar,
  //so we do it ourselves
  if (!tableUI) {
    comboBox.getInputMap().put(
       KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "showPopup"); //NOI18N
    comboBox.getActionMap().put("showPopup", new AbstractAction() {
      public void actionPerformed(ActionEvent ae) {
        if (!comboBox.isPopupVisible()) {
          comboBox.showPopup();
        } 
      }
    }); //NOI18N
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

protected void installKeyboardActions() {
  super.installKeyboardActions();
  //Basic UI won't install an action to open the combo on spacebar,
  //so we do it ourselves
  if (!tableUI) {
    comboBox.getInputMap().put(
       KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "showPopup"); //NOI18N
    comboBox.getActionMap().put("showPopup", new AbstractAction() {
      public void actionPerformed(ActionEvent ae) {
        if (!comboBox.isPopupVisible()) {
          comboBox.showPopup();
        } 
      }
    }); //NOI18N
  }
}

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

public PropertyEditorCellEditor() {
 this.tagsCellEditor = new JComboBox();
 this.tagsCellEditor.addActionListener( new SelectionAction() );
 this.tagsCellEditor.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
 this.tagsCellEditor.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), new CancelAction() );
 this.tagsCellEditor.setRenderer( new TagListComboBoxRenderer() );
 this.defaultCellEditor = new JTextField();
 this.defaultCellEditor.addActionListener( new SelectionAction() );
 this.defaultCellEditor.setBorder( BorderFactory.createEmptyBorder() );
}

代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler

private void initTabHandler() {
  this.combo.setFocusTraversalKeysEnabled(false);
  this.combo.getActionMap().put("tab-action", new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      combo.setSelectedItem(getText());
      Component component = getParent().getParent();
      if(component instanceof JTable) {
        JTable table = (JTable)component;
        if((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) {
          table.changeSelection(table.getEditingRow(), table.getEditingColumn()-1, false, false);
        } else {
          table.changeSelection(table.getEditingRow(), table.getEditingColumn()+1, false, false);
        }
      } else {
        if((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) {
          transferFocusBackward();
        } else {
          transferFocus();
        }
      }
    }
  });
  InputMap inputMap = this.combo.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
  inputMap.put(KeyStroke.getKeyStroke("TAB"), "tab-action");
  inputMap.put(KeyStroke.getKeyStroke("shift TAB"), "tab-action");
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

comboBox.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "showPopup"); //NOI18N
comboBox.getActionMap().put(
  "showPopup",
comboBox.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "selectPrevious"); //NOI18N
comboBox.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "selectNext"); //NOI18N
comboBox.getActionMap().put("selectPrevious", selectPrevAction); //NOI18N
comboBox.getActionMap().put("selectNext", selectNextAction); //NOI18N

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

/**
 * Creates a new <code>JPanel</code> with a double buffer and a flow layout.
 */
public TagListTableCellEditor() {
 setLayout( new BorderLayout() );
 tags = EMPTY_TAGS;
 eventListenerList = new EventListenerList();
 comboBox = new JComboBox();
 comboBox.addActionListener( new SelectionAction() );
 comboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
 comboBox.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), new CancelAction() );
 comboBox.setEditable( true );
 comboBox.setRenderer( new TagListComboBoxRenderer() );
 comboBox.setModel( new DefaultComboBoxModel( getTags() ) );
 comboBox.setEditable( true );
 add( comboBox, BorderLayout.CENTER );
 comboBox.requestFocus();
}

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

final JComboBox simpleBox = new JComboBox(Locale.getAvailableLocales());
 // this line configures the combo to only commit on ENTER 
 // or selecting an item from the list
 simpleBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
 //
 // simpleBox.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
 //     Collections.EMPTY_SET);
 // just noticed the OPs edit - following indeed is easier to disable _all_ traversal
 // keys with one statement
 simpleBox.setFocusTraversalKeysEnabled(false);
 Action myAction = new AbstractAction() {
   @Override
   public void actionPerformed(ActionEvent e) {
     LOG.info("got it!");
     simpleBox.transferFocus();
   }
 };
 simpleBox.getActionMap().put("tab-action", myAction);
 simpleBox.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
   .put(KeyStroke.getKeyStroke("TAB"), "tab-action");

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor

private JComboBox createComboBox( String[] choices, String defaultValue, Icon[] icons, Font font, FocusListener listener ) {
  JComboBox combo = new JComboBox(choices);
  combo.setSelectedItem(defaultValue);
  combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
  combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
  combo.setOpaque(false);
  combo.setFont( font );
  combo.addFocusListener( listener );
  combo.setEnabled( choices.length > 1 );
  combo.setRenderer( new DelegatingRenderer(combo.getRenderer(), choices, icons ) );
  InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
  inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N
  combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N
  return combo;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor

private JComboBox createComboBox(DataItem item, Font font, FocusListener listener) {
  List<ItemVariant> variants = item.getVariants();
  JComboBox combo = new JComboBox(variants.toArray());
  combo.setSelectedItem(item.getDefaultVariant());
  combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
  combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
  combo.setOpaque(false);
  combo.setFont(font);
  combo.addFocusListener(listener);
  combo.setEnabled(variants.size() > 1);
  combo.setRenderer(new DelegatingRenderer(combo.getRenderer(), variants, item.getVariantIcons()));
  InputMap inputMap = combo.getInputMap(JComboBox.WHEN_FOCUSED);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "showPopup"); //NOI18N
  combo.getActionMap().put("showPopup", new TogglePopupAction()); //NOI18N
  return combo;
}

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

public FormulaFragmentCellEditor() {
 setLayout( new BorderLayout() );
 final Action action = createExtendedEditorAction();
 this.eventListenerList = new EventListenerList();
 ellipsisButton = new EllipsisButton( "..." );
 ellipsisButton.addActionListener( action );
 comboBox = new JComboBox();
 final ComboBoxEditor boxEditor = comboBox.getEditor();
 if ( boxEditor instanceof BasicComboBoxEditor ) {
  final BasicComboBoxEditor basicComboBoxEditor = (BasicComboBoxEditor) boxEditor;
  final Object editorComponent = basicComboBoxEditor.getEditorComponent();
  if ( editorComponent instanceof JTextField ) {
   final JTextField editorTextField = (JTextField) editorComponent;
   editorTextField.setDocument( new NonFilteringPlainDocument() );
  }
 }
 comboBox.setRenderer( new EmptyValueListCellRenderer() );
 comboBox.addActionListener( new SelectionAction() );
 comboBox.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), new CancelAction() );
 comboBox.getInputMap().put( EditorMessages.getInstance().getKeyStroke
  ( "AbstractStringValueCellEditor.Popup.Accelerator" ), POPUP_EDITOR );
 comboBox.setBorder( BorderFactory.createEmptyBorder() );
 comboBox.setEditable( true );
 add( comboBox, BorderLayout.CENTER );
 add( ellipsisButton, BorderLayout.EAST );
 formulaContext = new DefaultFormulaContext();
 nullable = false;
}

代码示例来源:origin: JetBrains/jediterm

for (KeyStroke keyStroke : inputMap.allKeys()) {
  if (DefaultEditorKit.copyAction.equals(inputMap.get(keyStroke))) {
    comboBox.getInputMap().put(keyStroke, DefaultEditorKit.copyAction);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

exprList.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT),
    KeyEvent.VK_ENTER, KeyEvent.VK_ESCAPE, KeyEvent.VK_TAB
);

相关文章

JComboBox类方法