Java Code Examples for java.awt.event.KeyListener
The following are top voted examples for showing how to use
java.awt.event.KeyListener. These examples are extracted from open source projects.
You can vote up the examples you like and your votes will be used in our system to generate
more good examples.
Example 1
Project: incubator-netbeans File: WatchesColumnModels.java View source code | 7 votes |
@Override protected void processKeyEvent(KeyEvent e) { KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e); if (enter.equals(ks)) { // Prevent JComponent.processKeyBindings() to be called (it is called from // JComponent.processKeyEvent() ), notify only registered key listeners int id = e.getID(); for (KeyListener keyListener : getKeyListeners()) { switch(id) { case KeyEvent.KEY_TYPED: keyListener.keyTyped(e); break; case KeyEvent.KEY_PRESSED: keyListener.keyPressed(e); break; case KeyEvent.KEY_RELEASED: keyListener.keyReleased(e); break; } } if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) { synchronized(listeners) { List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners); for (CellEditorListener listener : list) { listener.editingStopped(new ChangeEvent(this)); } } } e.consume(); } else { super.processKeyEvent(e); } }
Example 2
Project: Cognizant-Intelligent-Test-Scripter File: StyledEditor.java View source code | 7 votes |
public KeyListener updateProviderOnSave() { return new KeyAdapter() { @Override public void keyPressed(KeyEvent ke) { if (isSave(ke)) { onSave(); } } }; }
Example 3
Project: incubator-netbeans File: ColumnModels.java View source code | 6 votes |
@Override protected void processKeyEvent(KeyEvent e) { KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e); if (enter.equals(ks)) { // Prevent JComponent.processKeyBindings() to be called (it is called from // JComponent.processKeyEvent() ), notify only registered key listeners int id = e.getID(); for (KeyListener keyListener : getKeyListeners()) { switch(id) { case KeyEvent.KEY_TYPED: keyListener.keyTyped(e); break; case KeyEvent.KEY_PRESSED: keyListener.keyPressed(e); break; case KeyEvent.KEY_RELEASED: keyListener.keyReleased(e); break; } } if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) { synchronized(listeners) { List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners); for (CellEditorListener listener : list) { listener.editingStopped(new ChangeEvent(this)); } } } e.consume(); } else { super.processKeyEvent(e); } }
Example 4
Project: Hotel-Properties-Management-System File: HotelPropertiesWindow.java View source code | 6 votes |
private KeyListener listenToKeysListener() { final KeyAdapter adapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String word = nameField.getText(); if (word.length() < 18) { hotelNameTitle.setText(word); hotelNameTitle.repaint(); } else { JOptionPane.showMessageDialog(modalFrame, "Hotel name maximum 18 charachter allowed!", JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE); } super.keyTyped(e); } }; return adapter; }
Example 5
Project: Hotel-Properties-Management-System File: AddUserWindow.java View source code | 6 votes |
private KeyListener validatorListener() { final KeyAdapter adapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { final EmailValidator validator = new EmailValidator(); if(validator.validate(emailField.getText())) { markerLbl.setVisible(false); infoLabel.setText(""); isValid = true; } else { markerLbl.setVisible(true); infoLabel.setText("Invalid email format!"); } } }; return adapter; }
Example 6
Project: freecol File: Canvas.java View source code | 6 votes |
/** * Checks if this {@code Canvas} contains any in game components. * * @return {@code true} if there is any in game components. */ public boolean containsInGameComponents() { KeyListener[] keyListeners = getKeyListeners(); if (keyListeners.length > 0) { return true; } MouseListener[] mouseListeners = getMouseListeners(); if (mouseListeners.length > 0) { return true; } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); if (mouseMotionListeners.length > 0) { return true; } return false; }
Example 7
Project: freecol File: Canvas.java View source code | 6 votes |
/** * Removes components that is only used when in game. */ public void removeInGameComponents() { // remove listeners, they will be added when launching the new game... KeyListener[] keyListeners = getKeyListeners(); for (KeyListener keyListener : keyListeners) { removeKeyListener(keyListener); } MouseListener[] mouseListeners = getMouseListeners(); for (MouseListener mouseListener : mouseListeners) { removeMouseListener(mouseListener); } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { removeMouseMotionListener(mouseMotionListener); } for (Component c : getComponents()) { removeFromCanvas(c); } }
Example 8
Project: Yass File: YassInput.java View source code | 6 votes |
/** * Description of the Method * * @param e Description of the Parameter */ public void fireKeyPressed(KeyEvent e) { for (Enumeration<KeyListener> en = listeners.elements(); en.hasMoreElements(); ) { KeyListener l = en.nextElement(); l.keyPressed(new KeyEvent((java.awt.Component) e.getSource(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); } }
Example 9
Project: Yass File: YassInput.java View source code | 6 votes |
/** * Description of the Method * * @param e Description of the Parameter */ public void fireKeyReleased(KeyEvent e) { for (Enumeration<KeyListener> en = listeners.elements(); en.hasMoreElements(); ) { KeyListener l = en.nextElement(); l.keyReleased(new KeyEvent((java.awt.Component) e.getSource(), KeyEvent.KEY_RELEASED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); } }
Example 10
Project: VTerminal File: Panel.java View source code | 6 votes |
/** * Adds an event listener to the Panel. * * @param eventListener * The event listener. * * @throws IllegalArgumentException * If the event listener isn't supported by this function. */ public void addListener(final EventListener eventListener) { if (eventListener instanceof KeyListener) { this.addKeyListener((KeyListener) eventListener); return; } if (eventListener instanceof MouseListener) { this.addMouseListener((MouseListener) eventListener); return; } if (eventListener instanceof MouseMotionListener) { this.addMouseMotionListener((MouseMotionListener) eventListener); return; } throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported."); }
Example 11
Project: VTerminal File: Panel.java View source code | 6 votes |
/** * Removes an event listener from the Panel. * * @param eventListener * The event listener. * * @throws IllegalArgumentException * If the event listener isn't supported by this function. */ public void removeListener(final EventListener eventListener) { if (eventListener instanceof KeyListener) { this.removeKeyListener((KeyListener) eventListener); return; } if (eventListener instanceof MouseListener) { this.removeMouseListener((MouseListener) eventListener); return; } if (eventListener instanceof MouseMotionListener) { this.removeMouseMotionListener((MouseMotionListener) eventListener); return; } throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported."); }
Example 12
Project: Cognizant-Intelligent-Test-Scripter File: SelectionManager.java View source code | 6 votes |
public void removeListener() { for (MouseListener ml : com.getMouseListeners()) { com.removeMouseListener(ml); } for (MouseMotionListener mml : com.getMouseMotionListeners()) { com.removeMouseMotionListener(mml); } for (KeyListener kl : com.getKeyListeners()) { com.removeKeyListener(kl); } reset(); com.repaint(); }
Example 13
Project: openjdk-jdk10 File: ComponentOperator.java View source code | 6 votes |
/** * Maps {@code Component.addKeyListener(KeyListener)} through queue */ public void addKeyListener(final KeyListener keyListener) { runMapping(new MapVoidAction("addKeyListener") { @Override public void map() { getSource().addKeyListener(keyListener); } }); }
Example 14
Project: FreeCol File: Canvas.java View source code | 6 votes |
/** * Checks if this {@code Canvas} contains any in game components. * * @return {@code true} if there is any in game components. */ public boolean containsInGameComponents() { KeyListener[] keyListeners = getKeyListeners(); if (keyListeners.length > 0) { return true; } MouseListener[] mouseListeners = getMouseListeners(); if (mouseListeners.length > 0) { return true; } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); if (mouseMotionListeners.length > 0) { return true; } return false; }
Example 15
Project: FreeCol File: Canvas.java View source code | 6 votes |
/** * Removes components that is only used when in game. */ public void removeInGameComponents() { // remove listeners, they will be added when launching the new game... KeyListener[] keyListeners = getKeyListeners(); for (KeyListener keyListener : keyListeners) { removeKeyListener(keyListener); } MouseListener[] mouseListeners = getMouseListeners(); for (MouseListener mouseListener : mouseListeners) { removeMouseListener(mouseListener); } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { removeMouseMotionListener(mouseMotionListener); } for (Component c : getComponents()) { removeFromCanvas(c); } }
Example 16
Project: VISNode File: CodeEditor.java View source code | 5 votes |
@Override public synchronized void addKeyListener(KeyListener keyListener) { textArea.addKeyListener(keyListener); }
Example 17
Project: incubator-netbeans File: SearchField.java View source code | 5 votes |
public void addSearchKeyListener(KeyListener listener) { txtSearch.addKeyListener(listener); }
Example 18
Project: incubator-netbeans File: ListView.java View source code | 5 votes |
private void setupSearch() { // Remove the default key listeners KeyListener[] keyListeners = getListeners(KeyListener.class); for (int i = 0; i < keyListeners.length; i++) { removeKeyListener(keyListeners[i]); } // Add new key listeners addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int modifiers = e.getModifiers(); int keyCode = e.getKeyCode(); if (((modifiers > 0) && (modifiers != KeyEvent.SHIFT_MASK)) || e.isActionKey()) { return; } char c = e.getKeyChar(); if (!Character.isISOControl(c) && (keyCode != KeyEvent.VK_SHIFT)) { searchTextField.setText(String.valueOf(c)); displaySearchField(); } } } ); // Create a the "multi-event" listener for the text field. Instead of // adding separate instances of each needed listener, we're using a // class which implements them all. This approach is used in order // to avoid the creation of 4 instances which takes some time SearchFieldListener searchFieldListener = new SearchFieldListener(); searchTextField.addKeyListener(searchFieldListener); searchTextField.addFocusListener(searchFieldListener); searchTextField.getDocument().addDocumentListener(searchFieldListener); }
Example 19
Project: JAddOn File: JUtils.java View source code | 5 votes |
public static Component setKeyListener(Component c, KeyListener kl) { if(c.getKeyListeners().length > 0) { for(KeyListener g : c.getKeyListeners()) { c.removeKeyListener(g); } } c.addKeyListener(kl); return c; }
Example 20
Project: Lunar File: Game.java View source code | 5 votes |
/** * Clear all key listeners. NOTE: this method will also remove the default listener. */ public void clearKeyListeners() { KeyListener[] listeners = frame.getKeyListeners(); for (KeyListener listener : listeners) { removeKeyListener(listener); } }
Example 21
Project: VASSAL-src File: PrivateMap.java View source code | 5 votes |
public synchronized void addKeyListener(KeyListener l) { if (listenersActive) { super.addKeyListener(l); } else { keyListeners.add(l); } }
Example 22
Project: VASSAL-src File: Map.java View source code | 5 votes |
/** * Save all current Key Listeners and remove them from the * map. Used by Traits that need to prevent Key Commands * at certain times. */ public void enableKeyListeners() { if (saveKeyListeners == null) return; for (KeyListener kl : saveKeyListeners) { theMap.addKeyListener(kl); } saveKeyListeners = null; }
Example 23
Project: VASSAL-src File: Map.java View source code | 5 votes |
/** * Restore the previously disabled KeyListeners */ public void disableKeyListeners() { if (saveKeyListeners != null) return; saveKeyListeners = theMap.getKeyListeners(); for (KeyListener kl : saveKeyListeners) { theMap.removeKeyListener(kl); } }
Example 24
Project: Hotel-Properties-Management-System File: Main_Blockade.java View source code | 5 votes |
private KeyListener customKeyListener() { final KeyAdapter adapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String modifiedQuery = "(?i)" + searchField.getText(); tableRowShorter.setRowFilter(RowFilter.regexFilter(modifiedQuery)); super.keyTyped(e); } }; return adapter; }
Example 25
Project: Hotel-Properties-Management-System File: Main_RoomCleaning.java View source code | 5 votes |
private KeyListener customKeyListener() { final KeyAdapter adapter = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String modifiedQuery = "(?i)" + searchField.getText(); tableRowShorter.setRowFilter(RowFilter.regexFilter(modifiedQuery)); super.keyTyped(e); } }; return adapter; }
Example 26
Project: Hotel-Properties-Management-System File: ExchangeWindow.java View source code | 5 votes |
private KeyListener getKeyListener() { KeyAdapter listener = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if(Character.isLetter(c) && !e.isAltDown()) { e.consume(); } } }; return listener; }
Example 27
Project: ISO8583 File: PnlMessageProperties.java View source code | 5 votes |
public PnlMessageProperties(KeyListener saveKeyListener) { setLayout(null); setBorder(new TitledBorder(null, "Message Properties", TitledBorder.LEADING, TitledBorder.TOP, null, null)); lblMsgType.setHorizontalAlignment(SwingConstants.RIGHT); lblMsgType.setBounds(12, 27, 102, 16); txtMsgType.setColumns(10); txtMsgType.setBounds(126, 24, 70, 22); txtMsgType.addKeyListener(saveKeyListener); lblHeaderEncoding.setHorizontalAlignment(SwingConstants.RIGHT); lblHeaderEncoding.setBounds(12, 56, 102, 16); cmbHeaderEncoding.setBounds(126, 53, 92, 22); EncodingEnum.addCmbItemList(cmbHeaderEncoding); lblBitmapEncoding.setHorizontalAlignment(SwingConstants.RIGHT); lblBitmapEncoding.setBounds(230, 56, 102, 16); cmbBitmapEncoding.setBounds(344, 53, 92, 22); EncodingEnum.addCmbItemList(cmbBitmapEncoding); add(lblMsgType); add(txtMsgType); add(lblHeaderEncoding); add(cmbHeaderEncoding); add(lblBitmapEncoding); add(cmbBitmapEncoding); setEnabled(false); }
Example 28
Project: freecol File: Canvas.java View source code | 5 votes |
/** * Shows the given video Component. * * @param vp The video Component. * @param ml A MouseListener for stopping the video. * @param kl A KeyListener for stopping the video. */ public void showVideoComponent(final Component vp, final MouseListener ml, final KeyListener kl) { addMouseListener(ml); addKeyListener(kl); addCentered(vp, JLayeredPane.PALETTE_LAYER); }
Example 29
Project: WordnetLoom File: MTextField.java View source code | 5 votes |
public MTextField(String text, KeyListener keyListener, int width, int height) { this(text); addKeyListener(keyListener); setPreferredSize(new Dimension(width, height)); setSize(new Dimension(width, height)); setFocusHandler(); }
Example 30
Project: NBANDROID-V2 File: KeyEditor.java View source code | 5 votes |
public KeyEditor(KeyListener listener) { initComponents(); passwd1.setText(""); passwd2.setText(""); passwd1.addKeyListener(listener); passwd2.addKeyListener(listener); alias.addKeyListener(listener); firstAndLastName.addKeyListener(listener); organizationUnit.addKeyListener(listener); organization.addKeyListener(listener); city.addKeyListener(listener); stateOrProvince.addKeyListener(listener); countryCode.addKeyListener(listener); }
Example 31
Project: Parabot-317-API-Minified-OS-Scape File: InternalKeyboard.java View source code | 5 votes |
public InternalKeyboard() { this.component = ServerEngine.getInstance().getCanvas(); this.keyboardlistener = component.getKeyListeners(); this.keyDispatcher = component.getKeyListeners()[0]; for (final KeyListener keyListener : component.getKeyListeners()) { component.removeKeyListener(keyListener); } component.addKeyListener(this); }
Example 32
Project: etomica File: DisplayCanvas.java View source code | 5 votes |
public void dispose() { ComponentListener[] listeners = getComponentListeners(); for (int i=0; i<listeners.length; i++) { removeComponentListener(listeners[i]); } MouseListener[] mlisteners = getMouseListeners(); for (int i=0; i<mlisteners.length; i++) { removeMouseListener(mlisteners[i]); } KeyListener[] klisteners = getKeyListeners(); for (int i=0; i<klisteners.length; i++) { removeKeyListener(klisteners[i]); } }
Example 33
Project: MaxSim File: CommonUI.java View source code | 5 votes |
public static JTextField createTextField(String text, KeyListener listener, boolean numbers) { JTextField field = new JTextField(text); field.setMinimumSize(textPrefSize); if(text.length() == 0) field.setPreferredSize(textPrefSize); if(listener != null) field.addKeyListener(listener); if(numbers) field.setDocument(new NumberDocument()); return field; }
Example 34
Project: openjdk-jdk10 File: CommonUI.java View source code | 5 votes |
public static JTextField createTextField(String text, KeyListener listener, boolean numbers) { JTextField field = new JTextField(text); field.setMinimumSize(textPrefSize); if(text.length() == 0) field.setPreferredSize(textPrefSize); if(listener != null) field.addKeyListener(listener); if(numbers) field.setDocument(new NumberDocument()); return field; }
Example 35
Project: openjdk-jdk10 File: ComponentOperator.java View source code | 5 votes |
/** * Maps {@code Component.removeKeyListener(KeyListener)} through queue */ public void removeKeyListener(final KeyListener keyListener) { runMapping(new MapVoidAction("removeKeyListener") { @Override public void map() { getSource().removeKeyListener(keyListener); } }); }
Example 36
Project: FreeCol File: Canvas.java View source code | 5 votes |
/** * Shows the given video Component. * * @param vp The video Component. * @param ml A MouseListener for stopping the video. * @param kl A KeyListener for stopping the video. */ public void showVideoComponent(final Component vp, final MouseListener ml, final KeyListener kl) { addMouseListener(ml); addKeyListener(kl); addCentered(vp, JLayeredPane.PALETTE_LAYER); }
Example 37
Project: incubator-netbeans File: SearchField.java View source code | 4 votes |
public void removeSearchKeyListener(KeyListener listener) { txtSearch.removeKeyListener(listener); }
Example 38
Project: incubator-netbeans File: FileSelectorField.java View source code | 4 votes |
@Override public void addKeyListener(KeyListener listener) { FileSelectorField.this.addKeyListener(listener); }
Example 39
Project: myster File: MessageWindow.java View source code | 4 votes |
public void addKeyListener(KeyListener l) { area.addKeyListener(l); }
Example 40
Project: incubator-netbeans File: QuickSearchTest.java View source code | 4 votes |
@Override public synchronized void removeKeyListener(KeyListener l) { addedKeyListeners.remove(l); super.removeKeyListener(l); }