List of usage examples for java.awt.event KeyAdapter KeyAdapter
KeyAdapter
From source file:edu.harvard.mcz.imagecapture.ui.FilteringGeogJComboBox.java
private void init() { countryLimit = ""; stateprovLimit = ""; cachedModel = null;/* www .j a v a 2 s .c om*/ lastTextLength = 0; // listen for loss of focus on the text field this.getEditor().getEditorComponent().addFocusListener(this); this.setEditable(true); final JTextField textfield = (JTextField) this.getEditor().getEditorComponent(); textfield.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent keyEvent) { log.debug(keyEvent); SwingUtilities.invokeLater(new Runnable() { public void run() { filter(textfield.getText(), true); } }); } }); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.ActionList.java
private void setupList() { list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override// ww w. ja va2 s . c o m public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { fireAction(); } } }); list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { fireAction(); } }); list.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getExtendedKeyCode() == KeyEvent.VK_SPACE) { fireAction(); } if (e.getExtendedKeyCode() == KeyEvent.VK_ENTER) { fireAction(); } } }); }
From source file:SwingTypeTester8.java
private void initComponents() { handler = new CharacterEventHandler(); producer = new RandomCharacterGenerator(); producer.setDone(true);// w w w . j a v a 2s .c o 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(); } }); }
From source file:de.tbuchloh.kiskis.gui.SearchDialog.java
@Override protected Component createMainPanel() { _query = new JTextField(25); _query.addActionListener(_findNextAction); _query.addKeyListener(new KeyAdapter() { @Override/*from www .ja v a2 s. co m*/ public void keyTyped(final KeyEvent e) { _findNextAction.setEnabled(_query.getText().length() > 0); } }); final JPanel panel = new JPanel(); panel.add(new JLabel(Messages.getString("SearchDialog.queryLabel_title"))); //$NON-NLS-1$ panel.add(_query); return panel; }
From source file:Splash.java
public Splash(JFrame f, String progName, String fileName) { super();/*ww w. j ava 2 s.c o m*/ // Can't use Swing border on JWindow: not a JComponent. // setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); im = new ImageIcon(fileName); if (im.getImageLoadStatus() != MediaTracker.COMPLETE) JOptionPane.showMessageDialog(f, "Warning: can't load image " + fileName + "\n" + "Please be sure you have installed " + progName + " correctly", "Warning", JOptionPane.WARNING_MESSAGE); int w = im.getIconWidth(), h = im.getIconHeight(); setSize(w, h); UtilGUI.center(this); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { dispose(); } }); addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { dispose(); } }); }
From source file:SwingTypeTester9.java
private void initComponents() { parent = this; handler = new CharacterEventHandler(); producer = new RandomCharacterGenerator(); producer.setDone(true);/*from w w w .j av a 2 s . c o 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) { new FeedbackFrame(parent).show(); } }); 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(); } }); }
From source file:com.openbravo.pos.customers.JCustomerFinder.java
private void init(DataLogicCustomers dlCustomers) { initComponents();//from w w w. ja va2 s. co m jScrollPane1.getVerticalScrollBar().setPreferredSize(new Dimension(35, 35)); m_jKeys.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent ke) { jcmdExecuteActionPerformed(null); } }); m_jtxtTaxID.addEditorKeys(m_jKeys); m_jtxtSearchKey.addEditorKeys(m_jKeys); m_jtxtName.addEditorKeys(m_jKeys); m_jtxtPostal.addEditorKeys(m_jKeys); m_jtxtPhone.addEditorKeys(m_jKeys); m_jtxtEmail.addEditorKeys(m_jKeys); m_jtxtTaxID.reset(); m_jtxtSearchKey.reset(); m_jtxtName.reset(); m_jtxtPostal.reset(); m_jtxtPhone.reset(); m_jtxtEmail.reset(); m_jtxtTaxID.activate(); lpr = new ListProviderCreator(dlCustomers.getCustomerList(), this); jListCustomers.setCellRenderer(new CustomerRenderer()); getRootPane().setDefaultButton(jcmdOK); selectedCustomer = null; }
From source file:ve.zoonosis.controller.seguridad.NuevoUsuarioController.java
@Override public final void inicializar() { activeInput(false);/*from w ww . j a va 2 s . c o m*/ cardNumber.setEnabled(true); if (entity == null) { entity = new Usuario(); limpiar(); buscar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { buscarPersona(); } }); limpiar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { limpiar(); } }); cardNumber.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { buscar.setEnabled(validarCedula()); if (e.getKeyCode() == KeyEvent.VK_ENTER && buscar.isEnabled()) { buscarPersona(); } } }); } else { activeInput(true); persona = entity.getPersona(); permiso.setEnabled(false); buscar.setVisible(false); limpiar.setVisible(false); BindObject bindObject2 = new BindObject(persona); Bindings.bind(cardNumber, bindObject2.getBind("cedula")); Bindings.bind(nombre, bindObject2.getBind("nombre")); Bindings.bind(apellido, bindObject2.getBind("apellido")); } aceptar.setEnabled(false); nombre.setMaxLength(45); apellido.setMaxLength(45); cardNumber.setMaxLength(20); usr.setMaxLength(20); iniForm(); try { rb = new RequestBuilder("services/administracion/PermisoWs/BuscarPermiso.php"); List<Permiso> permisos = rb.ejecutarJson(List.class, Permiso.class); if (permisos != null) { permisos.add(0, null); permiso.setModel(new ListComboBoxModel<>(permisos)); permiso.setSelectedIndex(-1); } } catch (URISyntaxException | RuntimeException ex) { LOG.LOGGER.log(Level.SEVERE, null, ex); } BindObject bindObject2 = new BindObject(entity); Bindings.bind(usr, bindObject2.getBind("nombre")); Bindings.bind(contrasena, bindObject2.getBind("contrasena")); Bindings.bind(fechaNacimiento, bindObject2.getBind("fechaNacimiento"), new SimpleDateFormat("dd/MM/yyyy")); Bindings.bind(permiso, bindObject2.getBind("permiso"), true); autoCreateValidateForm(Persona.class, Usuario.class); repeatPass.addKeyListener(formularioActionListener); usr.addKeyListener(formularioActionListener); DateTime d = new DateTime(); Date dia = new Date(d.getDayOfMonth() + "/" + d.getMonthOfYear() + "/" + (d.getYear() - 18)); fechaNacimiento.setMaxSelectableDate(dia); Date dia2 = new Date(d.getDayOfMonth() + "/" + d.getMonthOfYear() + "/" + (d.getYear() - 80)); fechaNacimiento.setMinSelectableDate(dia2); iniciarDialogo(); }
From source file:gtu._work.ui.StringArrayMakerUI.java
private void initGUI() { try {/*from ww w . j av a 2 s.c o m*/ BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jScrollPane2 = new JScrollPane(); jPanel1.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(525, 267)); { ListModel jList1Model = new DefaultListModel(); jList1 = new JList(); jScrollPane2.setViewportView(jList1); jList1.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(jList1).defaultJListKeyPressed(evt); } }); jList1.setModel(jList1Model); } } { jButton1 = new JButton(); jPanel1.add(jButton1, BorderLayout.NORTH); jButton1.setText("\u8cbc\u4e0a"); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1ActionPerformed(evt); } }); } { jPanel3 = new JPanel(); FlowLayout jPanel3Layout = new FlowLayout(); jPanel3Layout.setAlignment(FlowLayout.RIGHT); jPanel1.add(jPanel3, BorderLayout.WEST); jPanel3.setLayout(jPanel3Layout); jPanel3.setPreferredSize(new java.awt.Dimension(50, 291)); { jCheckBox1 = new JCheckBox(); jPanel3.add(jCheckBox1); jCheckBox1.setText("\\n"); } { jCheckBox2 = new JCheckBox(); jPanel3.add(jCheckBox2); jCheckBox2.setText("\\t"); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("jPanel2", null, jPanel2, null); { jButton2 = new JButton(); jPanel2.add(jButton2, BorderLayout.NORTH); jButton2.setText("\u7522\u751f"); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton2ActionPerformed(evt); } }); } { jScrollPane1 = new JScrollPane(); jPanel2.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(525, 291)); { jTextArea1 = new JTextArea(); jScrollPane1.setViewportView(jTextArea1); jTextArea1.setText(""); } } } } pack(); this.setSize(546, 382); } catch (Exception e) { // add your error handling code here e.printStackTrace(); } }
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 w w w. j ava 2 s . c om*/ 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); }