Example usage for java.awt.event KeyAdapter KeyAdapter

List of usage examples for java.awt.event KeyAdapter KeyAdapter

Introduction

In this page you can find the example usage for java.awt.event KeyAdapter KeyAdapter.

Prototype

KeyAdapter

Source Link

Usage

From source file:Main.java

public KeyTextComponent() {
    setBackground(Color.CYAN);/*from   ww w  .  jav a2 s .  c om*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_FIRST, keyText,
                        ActionEvent.ALT_MASK);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:Main.java

public KeyTextComponent() {
    setBackground(Color.CYAN);/*  ww w. j  a  va2s . c  o  m*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_FIRST, keyText,
                        System.currentTimeMillis() - 10, ActionEvent.ALT_MASK);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:Main.java

public void setEditor(ComboBoxEditor anEditor) {
    super.setEditor(anEditor);
    if (anEditor.getEditorComponent() instanceof JTextField) {
        tf = (JTextField) anEditor.getEditorComponent();
        tf.addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent ev) {
                char key = ev.getKeyChar();
                if (!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) {
                    return;
                }//from www. j a  v a 2s.  c  om
                String s = tf.getText();
                caretPos = tf.getCaretPosition();
                try {
                    String text = tf.getText(0, caretPos);
                    int n = getItemCount();
                    for (int i = 0; i < n; i++) {
                        int ind = ((String) getItemAt(i)).indexOf(text);
                        if (ind == 0) {
                            setSelectedIndex(i);
                            return;
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
}

From source file:KeyTextTester2.java

public KeyTextComponent2() {
    setBackground(Color.cyan);/*from w w w.j a  v a 2s . c  o  m*/
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocus();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

public static void setAutoUpperCase(final JTextField textField) {
    textField.addKeyListener(new KeyAdapter() {

        @Override//w  w  w  .  ja v a2s.  c o m
        public void keyReleased(KeyEvent e) {
            if (Character.isLetter(e.getKeyChar())) {
                convertToUpperCase((JTextField) e.getSource());
            }
        }

    });
}

From source file:com.konifar.material_icon_generator.FilterComboBox.java

private void initListener() {
    final JTextField textfield = (JTextField) this.getEditor().getEditorComponent();
    textfield.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent event) {
            switch (event.getKeyCode()) {
            case KeyEvent.VK_ENTER:
            case KeyEvent.VK_ESCAPE:
                requestFocus(false);/* w  ww.  j  a  v a2  s .  c om*/
                break;
            case KeyEvent.VK_UP:
            case KeyEvent.VK_DOWN:
                break;
            default:
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        filter(textfield.getText());
                    }
                });
            }
        }
    });

    getAccessibleContext().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(event.getPropertyName())
                    && AccessibleState.FOCUSED.equals(event.getNewValue())
                    && getAccessibleContext().getAccessibleChild(0) instanceof ComboPopup) {
                ComboPopup popup = (ComboPopup) getAccessibleContext().getAccessibleChild(0);
                JList list = popup.getList();

                if (list.getSelectedValue() != null) {
                    setSelectedItem(String.valueOf(list.getSelectedValue()));
                }
            }
        }
    });
}

From source file:com.mirth.connect.client.ui.alert.DefaultAlertEditPanel.java

private void initComponents() {
    setBackground(UIConstants.BACKGROUND_COLOR);
    setLayout(new MigLayout("insets 10", "grow", "[][grow][grow]"));

    nameLabel = new JLabel("Alert Name: ");
    nameTextField = new MirthTextField();

    nameTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent evt) {
            parent.setPanelName("Edit Alert - " + nameTextField.getText());
        }/*from   w w  w  .j a  v a 2  s  .com*/
    });

    enabledCheckBox = new MirthCheckBox("Enabled");
    enabledCheckBox.setBackground(UIConstants.BACKGROUND_COLOR);

    JPanel headerPanel = new JPanel();
    headerPanel.setBackground(UIConstants.BACKGROUND_COLOR);
    headerPanel.setLayout(new MigLayout("insets 0"));
    headerPanel.add(nameLabel, "");
    headerPanel.add(nameTextField, "width 500");
    headerPanel.add(enabledCheckBox, "wrap");

    alertTriggerPane = new DefaultAlertTriggerPane();

    alertChannelPane = new AlertChannelPane();

    alertActionPane = new AlertActionPane();

    add(headerPanel, "grow, span");
    add(alertTriggerPane, "grow, sg 1, height 100");
    add(alertChannelPane, "grow, sg 1, height 100, wrap");
    add(alertActionPane, "grow, sgy 1, width 100, height 100, span");
}

From source file:ImageSorter.java

/**
 * @param in/*ww w  .  j  a  v a  2  s  .  c  o  m*/
 * @param leftOut
 * @param rightOut
 */
public ImageSorter(String in, String leftOut, String rightOut) {
    super("ImageSorter");

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    inputs = new File(in).listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            String s = name.toLowerCase();

            return s.endsWith("jpg");
        }

    });

    leftOutput = new File(in, leftOut);
    rightOutput = new File(in, rightOut);

    leftOutput.mkdirs();
    rightOutput.mkdirs();

    assert leftOutput.canWrite();
    assert rightOutput.canWrite();

    panel.setPreferredSize(new Dimension(640, 480));
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(panel, BorderLayout.CENTER);

    panel.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                inputs[index].renameTo(new File(rightOutput, inputs[index].getName()));
            } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                inputs[index].renameTo(new File(leftOutput, inputs[index].getName()));
            }

            nextImage();
        }

    });

    panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            panel.requestFocusInWindow();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            panel.requestFocusInWindow();
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            panel.requestFocusInWindow();
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            panel.requestFocusInWindow();
        }

    });

    panel.requestFocusInWindow();

    nextImage();

    pack();
    setVisible(true);
}

From source file:MiniBrowser.java

public MiniBrowser() {
    setSize(640, 480);/*from w ww  .  j a v a2 s  .  com*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel buttonPanel = new JPanel();
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionBack();
        }
    });
    backButton.setEnabled(false);
    buttonPanel.add(backButton);
    forwardButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionForward();
        }
    });
    forwardButton.setEnabled(false);
    buttonPanel.add(forwardButton);
    locationTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                actionGo();
            }
        }
    });
    buttonPanel.add(locationTextField);
    JButton goButton = new JButton("GO");
    goButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionGo();
        }
    });
    buttonPanel.add(goButton);
    displayEditorPane.setContentType("text/html");
    displayEditorPane.setEditable(false);
    displayEditorPane.addHyperlinkListener(this);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(new JScrollPane(displayEditorPane), BorderLayout.CENTER);
}

From source file:com.aw.swing.mvp.cmp.RowSelectorMediator.java

public RowSelectorMediator(JTextField textField, JTable table, int columnIndex) {
    this.textField = textField;
    this.table = table;
    this.columnIndex = columnIndex;

    documentListener = new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            textFieldChanged(e);/*from w  ww.  jav a  2s .  c om*/
        }

        public void insertUpdate(DocumentEvent e) {
            textFieldChanged(e);
        }

        public void removeUpdate(DocumentEvent e) {
            textFieldChanged(e);
        }
    };

    textField.getDocument().addDocumentListener(documentListener);

    //Add the keylistener to process the Up, Down, PgUp and PgDn keys events
    textField.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            textFieldKeyPressed(e);
        }

        public void keyReleased(KeyEvent e) {
        }
    });
}