List of usage examples for java.awt.event KeyEvent getKeyChar
public char getKeyChar()
From source file:edu.ku.brc.af.ui.db.JEditComboBox.java
protected KeyAdapter createKeyAdapter() { return new KeyAdapter() { @Override/*w w w. j a va 2s .c o m*/ public void keyReleased(KeyEvent ev) { char key = ev.getKeyChar(); if (ev.getKeyCode() == clearKeyStroke.getKeyCode()) { int selectedIndex = getSelectedIndex(); if (selectedIndex > -1 && dbAdapter != null && textField != null && textField.getText().length() == 0 && !dbAdapter.isReadOnly()) { // delete item PickListItem item = (PickListItem) getSelectedItem(); dbAdapter.getList().remove(item); } } else if (!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) { if (ev.getKeyCode() == KeyEvent.VK_ENTER) { addNewItemFromTextField(); } } else { if (textField != null) { if (getSelectedIndex() > -1) { int pos = textField.getCaretPosition(); String currentText = textField.getText(); setSelectedIndex(-1); textField.setText(currentText); textField.moveCaretPosition(pos); textField.setSelectionStart(pos); textField.setSelectionEnd(pos); } } else { setSelectedIndex(-1); } } } }; }
From source file:com.github.fritaly.dualcommander.TabbedPane.java
@Override public void keyReleased(KeyEvent e) { if (e.getSource() == getSelectedComponent()) { // Propagate the event to our listeners processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); }// www. j a va 2s. c om }
From source file:com.github.fritaly.dualcommander.TabbedPane.java
@Override public void keyTyped(KeyEvent e) { if (e.getSource() == getSelectedComponent()) { // Propagate the event to our listeners processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); }/*from ww w . j av a 2 s . c om*/ }
From source file:KeyEventDemo.java
protected void displayInfo(KeyEvent e, String s) { String keyString, modString, tmpString, actionString, locationString; //You should only rely on the key char if the event //is a key typed event. int id = e.getID(); if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else {// w w w . j av a 2 s. co m int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiers = e.getModifiersEx(); modString = "modifiers = " + modifiers; tmpString = KeyEvent.getModifiersExText(modifiers); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no modifiers)"; } actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(s + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:org.apache.cayenne.modeler.util.PathChooserComboBoxCellEditor.java
protected void initializeCombo(CayenneTableModel model, int row, final JTable table) { Object currentNode = getCurrentNodeToInitializeCombo(model, row); String dbAttributePath = getPathToInitializeCombo(model, row); List<String> nodeChildren = getChildren(currentNode, dbAttributePath); this.table = table; comboBoxPathChooser = Application.getWidgetFactory().createComboBox(nodeChildren, false); comboBoxPathChooser.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { @Override//from ww w . j a va 2s . c o m public void keyReleased(KeyEvent event) { if (event.getKeyCode() == KeyEvent.VK_ENTER) { enterPressed(table); return; } parsePathString(event.getKeyChar()); } }); AutoCompletion.enable(comboBoxPathChooser, true, true); ((JComponent) comboBoxPathChooser.getEditor().getEditorComponent()).setBorder(null); comboBoxPathChooser.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); comboBoxPathChooser.setRenderer(new PathChooserComboBoxCellRenderer()); comboBoxPathChooser.addActionListener(this); comboBoxPathChooser.addPopupMenuListener(this); }
From source file:Console.java
public void keyTyped(KeyEvent e) { int keyChar = e.getKeyChar(); if (keyChar == 0x8 /* KeyEvent.VK_BACK_SPACE */) { if (outputMark == getCaretPosition()) { e.consume();//from w ww .j a v a 2s .co m } } else if (getCaretPosition() < outputMark) { setCaretPosition(outputMark); } }
From source file:com.polivoto.vistas.Acceso.java
private void usrTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_usrTextFieldKeyTyped char c = evt.getKeyChar(); if (c == '\n') { pwdTextField.selectAll();/*from w w w .ja v a 2 s . com*/ } }
From source file:com.polivoto.vistas.Acceso.java
private void usrTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_usrTextFieldKeyPressed char c = evt.getKeyChar(); if (c == '\n') { (new Thread(new Loading())).start(); botonClicked();//from w w w.j a v a 2 s .c o m } }
From source file:com.polivoto.vistas.Acceso.java
private void pwdTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pwdTextFieldKeyPressed char c = evt.getKeyChar(); if (c == '\n') { (new Thread(new Loading())).start(); botonClicked();/*from w w w.ja va2s . com*/ } }
From source file:SwingTypeTester8.java
private void initComponents() { handler = new CharacterEventHandler(); producer = new RandomCharacterGenerator(); producer.setDone(true);//from w w w. j a v a 2s. co m producer.start(); displayCanvas = new AnimatedCharacterDisplayCanvas(producer); feedbackCanvas = new CharacterDisplayCanvas(this); quitButton = new JButton(); startButton = new JButton(); stopButton = new JButton(); score = new ScoreLabel(producer, this); Container pane = getContentPane(); JPanel p1 = new JPanel(); p1.setLayout(new BoxLayout(p1, BoxLayout.PAGE_AXIS)); p1.add(displayCanvas); p1.add(feedbackCanvas); JPanel p2 = new JPanel(); score.setText(" "); score.setFont(new Font("MONOSPACED", Font.BOLD, 30)); p2.add(score); startButton.setText("Start"); p2.add(startButton); stopButton.setText("Stop"); stopButton.setEnabled(false); p2.add(stopButton); quitButton.setText("Quit"); p2.add(quitButton); p1.add(p2); pane.add(p1, BorderLayout.NORTH); pack(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { quit(); } }); feedbackCanvas.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent ke) { char c = ke.getKeyChar(); if (c != KeyEvent.CHAR_UNDEFINED) newCharacter((int) c); } }); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { displayCanvas.setDone(false); producer.setDone(false); score.resetScore(); startButton.setEnabled(false); stopButton.setEnabled(true); feedbackCanvas.setEnabled(true); feedbackCanvas.requestFocus(); } }); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { startButton.setEnabled(true); stopButton.setEnabled(false); producer.setDone(true); displayCanvas.setDone(true); feedbackCanvas.setEnabled(false); } }); quitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { quit(); } }); }