java.awt.event.KeyAdapter Java Examples

The following examples show how to use java.awt.event.KeyAdapter. 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: bug6578666.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void createGui() {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    tree = new JTree();
    frame.add(tree);

    tree.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            tree.updateUI();
        }
    });

    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example #2
Source File: DisplayChangeVITest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example #3
Source File: SwingWebWrapper.java    From CrossMobile with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({"OverridableMethodCallInConstructor"})
public NativeW() {
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            //    TextFieldEventPropagate.consumeKeyEvent(pwidget.get(), widget.getCaretPosition(), e.getKeyChar(), true);    // Always click event
        }
    });
    addPropertyChangeListener("page", (PropertyChangeEvent evt) -> {
        isLoading = false;
        // Take care of event that the page  has loaded
        UIWebView wv = getIOSWidget();
        if (wv == null)
            return;
        Native.graphics().refreshDisplay();

        UIWebViewDelegate del = wv.delegate();
        if (del != null)
            del.didFinishLoad(wv);
    });
    setEditable(false);
    addHyperlinkListener(SwingWebWrapper.this);
}
 
Example #4
Source File: DoubleField.java    From Explvs-AIO with MIT License 6 votes vote down vote up
public DoubleField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new DoubleDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example #5
Source File: DisplayChangeVITest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example #6
Source File: RSUnitField.java    From Explvs-AIO with MIT License 6 votes vote down vote up
public RSUnitField() {
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });

    setPlaceholder("100 / 1.2k / etc.");
}
 
Example #7
Source File: ItemField.java    From Explvs-AIO with MIT License 6 votes vote down vote up
public ItemField() {
    setColumns(20);
    addPosibilities(ItemGuide.getAllGEItems().keySet());
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateItemNameField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateItemNameField();
        }
    });
}
 
Example #8
Source File: DisplayChangeVITest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example #9
Source File: OQLControllerUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Presenter(final QueryUI queryUI) {
    super();
    setText(Bundle.OQLControllerUI_ControllerName());
    setToolTipText(Bundle.OQLControllerUI_ControllerDescr());
    setIcon(OQL_ICON);

    addKeyListener(new KeyAdapter() {
        public void keyTyped(final KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    queryUI.requestFocus();
                    queryUI.addToQuery(e.getKeyChar());
                }
            });
        }
    });
}
 
Example #10
Source File: HotelPropertiesWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 6 votes vote down vote up
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 #11
Source File: DisplayChangeVITest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example #12
Source File: HexOrDecimalInput.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public HexOrDecimalInput(Long initialValue) {
	super();
	currentValue = initialValue;
	setDocument(new MyDocument());
	updateText();
	setToolTipText("Press 'M' to toggle Hex or Decimal Mode");
	addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			if (e.getKeyCode() == KeyEvent.VK_M) {
				toggleMode();
				repaint();
			}
		}

	});
}
 
Example #13
Source File: AddUserWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 6 votes vote down vote up
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 #14
Source File: Oculus.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
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 #15
Source File: DisplayChangeVITest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example #16
Source File: DisplayChangeVITest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example #17
Source File: IconPreviewPanel.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
private void init() {
    JScrollPane pane = new JScrollPane();
    list = new JList(dataModel);
    list.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_F5) {
                try {
                    data = null;
                    loadImages();
                } catch (IOException e1) {
                    e1.printStackTrace();
                    JOptionPane.showMessageDialog(null, e1
                            .getLocalizedMessage());
                }
                list.setModel(dataModel);
                list.updateUI();
            }
        }
    });
    list.setCellRenderer(new IconRenderer());
    pane.setViewportView(list);
    for (int i = 0; i < data.size(); i++) {
    }
    this.add(pane, BorderLayout.CENTER);
}
 
Example #18
Source File: RSUnitField.java    From Explvs-AIO with MIT License 6 votes vote down vote up
public RSUnitField() {
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });

    setPlaceholder("100 / 1.2k / etc.");
}
 
Example #19
Source File: DisplayChangeVITest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
DisplayChangeVITest() {
    selectDisplayModes();
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                synchronized (lock) {
                    done = true;
                }
            }
        }
    });
    sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    sprite.getRaster().getDataBuffer();
    Graphics g = sprite.getGraphics();
    g.setColor(Color.yellow);
    g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
 
Example #20
Source File: DoubleField.java    From Explvs-AIO with MIT License 6 votes vote down vote up
public DoubleField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new DoubleDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example #21
Source File: TextualDocumentView.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void initListeners() {
  // textView.addComponentListener(new ComponentAdapter(){
  // public void componentResized(ComponentEvent e){
  // try{
  // scroller.getViewport().setViewPosition(
  // textView.modelToView(0).getLocation());
  // scroller.paintImmediately(textView.getBounds());
  // }catch(BadLocationException ble){
  // //ignore
  // }
  // }
  // });

  // stop control+H from deleting text and transfers the key to the
  // parent
  textView.addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if(e.getKeyCode() == KeyEvent.VK_H && e.isControlDown()) {
        getGUI().dispatchEvent(e);
        e.consume();
      }
    }
  });
}
 
Example #22
Source File: IntegerField.java    From Explvs-AIO with MIT License 6 votes vote down vote up
public IntegerField() {
    ((AbstractDocument) getDocument()).setDocumentFilter(new IntegerDocumentFilter());

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateField();
        }
    });
}
 
Example #23
Source File: ItemField.java    From Explvs-AIO with MIT License 6 votes vote down vote up
public ItemField() {
    setColumns(20);
    addPosibilities(ItemGuide.getAllGEItems().keySet());
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            validateItemNameField();
        }
    });

    setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            return validateItemNameField();
        }
    });
}
 
Example #24
Source File: CustomCellEditor.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
public CustomCellEditor(final JTable table) {
    super(new JTextField());

    final JTextField component = (JTextField) getComponent();
    component.setName("Table.editor");

    component.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent e) {
            if ((e.getModifiers() & InputEvent.CTRL_MASK) != 0) {
                if (e.getKeyCode() == ';') {
                    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                    component.setText(format.format(new Date()));

                } else if (e.getKeyCode() == 'v' || e.getKeyCode() == 'V') {
                    component.paste();

                } else if (e.getKeyCode() == 'c' || e.getKeyCode() == 'C') {
                    component.copy();

                } else if (e.getKeyCode() == 'x' || e.getKeyCode() == 'X') {
                    component.cut();

                }
            }

            super.keyPressed(e);
        }

    });

    component.setComponentPopupMenu(new TextFieldPopupMenu());
}
 
Example #25
Source File: Main_RoomCleaning.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: DeclarationPanel.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a DeclarationPanel.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 */
public DeclarationPanel(FreeColClient freeColClient) {
    super(freeColClient);

    Image image = ImageLibrary.getUnscaledImage("image.flavor.Declaration");
    setSize(image.getWidth(null), image.getHeight(null));
    setOpaque(false);
    setBorder(null);
    addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent k) {
                getGUI().removeComponent(DeclarationPanel.this);
            }
        });
    addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                getGUI().removeComponent(DeclarationPanel.this);
            }
        });

    final SignaturePanel signaturePanel = new SignaturePanel();
    signaturePanel.initialize(getMyPlayer().getName());
    signaturePanel.setLocation((getWidth()-signaturePanel.getWidth()) / 2,
        (getHeight() + SIGNATURE_Y - signaturePanel.getHeight()) / 2 - 15);
    signaturePanel.addActionListener(this);

    add(signaturePanel);

    Timer t = new Timer(START_DELAY, (ActionEvent ae) -> {
            signaturePanel.startAnimation();
        });
    t.setRepeats(false);
    t.start();
}
 
Example #27
Source File: ExchangeWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
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 #28
Source File: FindPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form FindPanel. */
public FindPanel() {
    initComponents ();
    initAccessibility ();
    findCombo.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
         public void keyTyped(KeyEvent evt) {
            if (evt.getKeyChar() == '\n') {
                findButton.doClick(20);
                evt.consume();
            }
        }
    });
}
 
Example #29
Source File: EntityResourcesSetupPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addComboBoxListener(JComboBox comboBox) {
    JTextComponent text = ((JTextComponent) comboBox.getEditor().getEditorComponent());
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent event) {
            //updatePreview();
        }
    });
}
 
Example #30
Source File: ChangePasswordWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
public void keyListenerForFields(JPasswordField passwordField) {
	KeyAdapter myAdapter = new KeyAdapter() {

		@Override
		public void keyTyped(KeyEvent e) {
			infoLabel.setText(null);
			markerLbl.setVisible(false);
			super.keyTyped(e);
		}
	};
	passwordField.addKeyListener(myAdapter);
}