Java Code Examples for java.awt.Component#addKeyListener()
The following examples show how to use
java.awt.Component#addKeyListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GradientSlider.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
public ColorPickerPopup() { boolean includeOpacity = MultiThumbSliderUI .getProperty(GradientSlider.this, "GradientSlider.includeOpacity", "true").equals("true"); mini = new ColorPicker(false, includeOpacity); mini.setMode(ColorPicker.HUE); mini.setPreferredSize(new Dimension(220, 200)); PropertyChangeListener p = evt -> { ColorPicker p1 = (ColorPicker) evt.getSource(); Color[] colors = getColors(); colors[lastSelectedThumb] = p1.getColor(); setValues(getThumbPositions(), colors); }; mini.addPropertyChangeListener(ColorPicker.SELECTED_COLOR_PROPERTY, p); mini.addPropertyChangeListener(ColorPicker.OPACITY_PROPERTY, p); for (int a = 0; a < mini.getComponentCount(); a++) { Component c = mini.getComponent(a); c.addKeyListener(commitListener); } add(mini); }
Example 2
Source File: EditableLabel.java From jace with GNU General Public License v2.0 | 6 votes |
public EditableLabel(JLabel label, Component edit, int width, int horizontalPadding, int verticalPadding, Object owner, String property) { ownerObject = owner; this.width = width; objectProperty = property; addMouseListener(this); edit.addFocusListener(this); addFocusListener(this); layout = new CardLayout(horizontalPadding, verticalPadding); setLayout(layout); add(label, cards.label.toString()); add(edit, cards.edit.toString()); labelComponent = label; editComponent = edit; deactivateEdit(); setBackground(UserInterface.Theme.background.color); label.setForeground(UserInterface.Theme.foreground.color); label.setOpaque(false); edit.setBackground(UserInterface.Theme.backgroundEdit.color); edit.setForeground(UserInterface.Theme.foregroundEdit.color); edit.setFocusTraversalKeysEnabled(false); edit.addKeyListener(NAV_LISTENER); label.addKeyListener(NAV_LISTENER); this.addKeyListener(NAV_LISTENER); }
Example 3
Source File: ReplaceDialog.java From visualvm with GNU General Public License v2.0 | 6 votes |
private void registerKeyAction(Component c) { if (c instanceof ReplaceDialog == false) { c.removeKeyListener(this); c.addKeyListener(this); } if (c instanceof Container) { Container cnt = (Container) c; cnt.removeContainerListener(this); cnt.addContainerListener(this); Component[] ch = cnt.getComponents(); for (int i = 0; i < ch.length; i++) { registerKeyAction(ch[i]); } } }
Example 4
Source File: EscapableDialog.java From rest-client with Apache License 2.0 | 6 votes |
private void registerKeyAction(Component c) { if (c instanceof EscapableDialog == false) { c.removeKeyListener(this); c.addKeyListener(this); } if (c instanceof Container) { Container cnt = (Container) c; cnt.removeContainerListener(this); cnt.addContainerListener(this); Component[] ch = cnt.getComponents(); for (int i = 0; i < ch.length; i++) { registerKeyAction(ch[i]); } } }
Example 5
Source File: Oculus.java From arcusplatform with Apache License 2.0 | 6 votes |
public static void invokeOnEnter(Component c, Runnable action) { if (c instanceof JTextField) { ((JTextField)c).addActionListener((evt) -> action.run()); } else if (c instanceof AbstractButton) { ((AbstractButton)c).addActionListener((evt) -> action.run()); } else { c.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if(e.getModifiers() == 0 && e.getKeyCode() == KeyEvent.VK_ENTER) { action.run(); } } }); } }
Example 6
Source File: HighlightNode.java From ontopia with Apache License 2.0 | 5 votes |
private void listenTo(Component component) { component.addKeyListener(this); if (component instanceof Container) { Container container = (Container)component; container.addContainerListener(this); Component components[] = container.getComponents(); for (int i = 0; i < components.length; i++) { Component currentComponent = components[i]; listenTo(currentComponent); } } }
Example 7
Source File: DefaultKeyHandler.java From nextreports-designer with Apache License 2.0 | 5 votes |
/** * This method registers a component for the mapped actions. * * @param component component */ public void registerComponent(Component component) { component.addKeyListener(this); if (component instanceof Container) { Component[] comps = ((Container) component).getComponents(); for (Component comp : comps) { registerComponent((comp)); } } }
Example 8
Source File: GOSwingEventConverter.java From settlers-remake with MIT License | 5 votes |
/** * Creates a new event converter, that converts swing events to go events. * * @param component * The component. * @param provider * THe provider to which to send the events. */ public GOSwingEventConverter(Component component, GOEventHandlerProvider provider) { super(provider); component.setFocusTraversalKeysEnabled(false); component.addKeyListener(this); component.addMouseListener(this); component.addMouseMotionListener(this); component.addMouseWheelListener(this); component.addHierarchyListener(this); addReplaceRule(new EventReplacementRule(ReplacableEvent.DRAW, Replacement.COMMAND_SELECT, MOUSE_TIME_TRSHOLD, MOUSE_MOVE_TRESHOLD)); addReplaceRule(new EventReplacementRule(ReplacableEvent.PAN, Replacement.COMMAND_ACTION, MOUSE_TIME_TRSHOLD, MOUSE_MOVE_TRESHOLD)); }
Example 9
Source File: SimpleNeuriteTracer.java From SNT with GNU General Public License v3.0 | 5 votes |
/** * This method will remove the existing keylisteners from the component 'c', * tells 'firstKeyListener' to call those key listeners if it has not dealt * with the key, and then sets 'firstKeyListener' as the key listener for * 'c' */ public static void setAsFirstKeyListener(final Component c, final QueueJumpingKeyListener firstKeyListener) { final KeyListener[] oldKeyListeners = c.getKeyListeners(); for (final KeyListener kl : oldKeyListeners) { c.removeKeyListener(kl); } firstKeyListener.addOtherKeyListeners(oldKeyListeners); c.addKeyListener(firstKeyListener); }
Example 10
Source File: ClarifyingKeyListener.java From SNT with GNU General Public License v3.0 | 5 votes |
public void addKeyAndContainerListenerRecursively(final Component c) { c.addKeyListener(this); if (c instanceof Container) { final Container container = (Container) c; container.addContainerListener(this); final Component[] children = container.getComponents(); for (int i = 0; i < children.length; i++) { addKeyAndContainerListenerRecursively(children[i]); } } }
Example 11
Source File: KeyInputManager.java From ontopia with Apache License 2.0 | 5 votes |
private void listenTo(Component component) { component.addKeyListener(this); if (component instanceof Container) { Container container = (Container)component; container.addContainerListener(this); Component components[] = container.getComponents(); for (int i = 0; i < components.length; i++) { Component currentComponent = components[i]; listenTo(currentComponent); } } }
Example 12
Source File: BaselineCorrectorSetupDialog.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
private void set_VK_ESCAPE_KeyListener() { // Set VK_ESCAPE KeyEvent listeners List<Component> comps = BaselineCorrectorSetupDialog.getAllComponents(BaselineCorrectorSetupDialog.this); for (Component c : comps) { c.addKeyListener(BaselineCorrectorSetupDialog.this.keyListener); } }
Example 13
Source File: ModifierTracker.java From pumpernickel with MIT License | 5 votes |
private static void track(Component c) { c.addKeyListener(keyListener); if (c instanceof Container) { Container container = (Container) c; for (int a = 0; a < container.getComponentCount(); a++) { track(container.getComponent(a)); } } }
Example 14
Source File: MouseModifiersInKeyEvent.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void createAndShowGUI() { f = new JFrame(); final Component component = new JTextField(); component.addKeyListener(new MyKeyListener()); f.add(component); f.setSize(300, 300); f.setLocationRelativeTo(null); f.setAlwaysOnTop(true); f.setVisible(true); }
Example 15
Source File: SaveableSectionInnerPanel.java From netbeans with Apache License 2.0 | 5 votes |
protected void disableEnterKey() { Component[] components = this.getComponents(); listener = new EnterKeyListener(); for (int i = 0; i < components.length; i++) { Component component = components[i]; if (component.isFocusable() && !(component instanceof JLabel)) { KeyListener kl = (KeyListener) WeakListeners.create(KeyListener.class, listener, component); component.addKeyListener(kl); } } }
Example 16
Source File: AWTKeyInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void bind(Component component) { super.bind(component); component.addKeyListener(this); }
Example 17
Source File: KeyBindingActionManager.java From tuxguitar with GNU Lesser General Public License v2.1 | 4 votes |
public void appendListenersTo(Component control){ control.addKeyListener(this.listener); }
Example 18
Source File: InputHandler.java From minicraft-plus-revived with GNU General Public License v3.0 | 4 votes |
public InputHandler(Component inputSource) { this(); inputSource.addKeyListener(this); //add key listener to game //inputSource.addMouseListener(this); //add mouse listener to game (though it's never used) }
Example 19
Source File: FindAndReplaceDialog.java From 3Dscript with BSD 2-Clause "Simplified" License | 4 votes |
public FindAndReplaceDialog(final AnimationEditor editor) { super(editor); textEditor = editor; final Container root = getContentPane(); root.setLayout(new GridBagLayout()); final JPanel text = new JPanel(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.gridx = c.gridy = 0; c.gridwidth = c.gridheight = 1; c.weightx = c.weighty = 1; c.ipadx = c.ipady = 1; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; searchField = createField("Find Next", text, c, null); replaceField = createField("Replace with", text, c, this); c.gridwidth = 4; c.gridheight = c.gridy; c.gridx = c.gridy = 0; c.weightx = c.weighty = 1; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; root.add(text, c); c.gridy = c.gridheight; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.001; matchCase = createCheckBox("Match Case", root, c); regex = createCheckBox("Regex", root, c); forward = createCheckBox("Search forward", root, c); forward.setSelected(true); c.gridx = 0; c.gridy++; markAll = createCheckBox("Mark All", root, c); wholeWord = createCheckBox("Whole Word", root, c); c.gridx = 4; c.gridy = 0; findNext = createButton("Find Next", root, c); replace = createButton("Replace", root, c); replaceAll = createButton("Replace All", root, c); cancel = createButton("Cancel", root, c); setResizable(true); pack(); getRootPane().setDefaultButton(findNext); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); final KeyAdapter listener = new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) dispose(); } }; for (final Component component : getContentPane().getComponents()) component.addKeyListener(listener); searchField.addKeyListener(listener); replaceField.addKeyListener(listener); }
Example 20
Source File: HardLayoutPane.java From DroidUIBuilder with Apache License 2.0 | 3 votes |
/** * 给除文本组件外的其它加入本面板的组件添加“回车转移焦点到下一组件”的监听器.<br> * 注:文本组件的相似监听器已经利用其全局action map在LNF UI中调用实现了. * * @param willBeAddTo 要给其添加“回车转移焦点到下一组件”的监听器的组件 * @see LaunchRoot#spesificTextField() * @see TextFocusAction#installTextActionMap() */ private void addEnterKeyTransferFocusImplExceptText(Component willBeAddTo) { //文本组件不需要添加了 if(!(willBeAddTo instanceof javax.swing.text.JTextComponent)) willBeAddTo.addKeyListener(TransferFocusImpl.SINGLETON); }