Example usage for java.awt.event KeyEvent getSource

List of usage examples for java.awt.event KeyEvent getSource

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:Main.java

public static void retargetKeyEvent(KeyEvent e, Component target) {
    if ((target == null) || (target == e.getSource())) {
        return;/*from   w  w  w  .  j a v  a2 s  . c  o  m*/
    }

    target.dispatchEvent(e);
}

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

public static void setAutoUpperCase(final JTextArea textArea) {
    textArea.addKeyListener(new KeyAdapter() {

        @Override// ww w.jav a  2  s  .co  m
        public void keyReleased(KeyEvent e) {
            if (Character.isLetter(e.getKeyChar())) {
                convertToUpperCase((JTextArea) e.getSource());
            }
        }

    });
}

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

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

        @Override/*from  w w w  .  ja  va 2  s  .c  om*/
        public void keyReleased(KeyEvent e) {
            if (Character.isLetter(e.getKeyChar())) {
                convertToUpperCase((JTextField) e.getSource());
            }
        }

    });
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    JComboBox cb = (JComboBox) evt.getSource();

    int curIx = cb.getSelectedIndex();

    char ch = evt.getKeyChar();

    JComboBox.KeySelectionManager ksm = cb.getKeySelectionManager();
    if (ksm != null) {
        int ix = ksm.selectionForKey(ch, cb.getModel());
        boolean noMatch = ix < 0;
        boolean uniqueItem = ix == curIx;

        if (noMatch || !uniqueItem) {
            cb.showPopup();//from  w  ww  .  ja  v  a 2s.co  m
        }
    }
}

From source file:MyKeyListener.java

public void keyTyped(KeyEvent evt) {
    JTextComponent c = (JTextComponent) evt.getSource();
    char ch = evt.getKeyChar();

    if (Character.isLowerCase(ch) == false) {
        return;/*from  w ww  .j  av  a  2s .co m*/
    }
    try {
        c.getDocument().insertString(c.getCaretPosition(), "" + Character.toUpperCase(ch), null);
        evt.consume();
    } catch (BadLocationException e) {
    }
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    JComboBox cb = (JComboBox) evt.getSource();

    int curIx = cb.getSelectedIndex();

    char ch = evt.getKeyChar();

    JComboBox.KeySelectionManager ksm = cb.getKeySelectionManager();
    if (ksm != null) {
        // Determine if another item has the same prefix
        int ix = ksm.selectionForKey(ch, cb.getModel());
        boolean noMatch = ix < 0;
        boolean uniqueItem = ix == curIx;

        // Display menu if no matching items or the if the selection is not unique
        if (noMatch || !uniqueItem) {
            cb.showPopup();/*ww  w . j  a v a2 s  .c  o m*/
        }
    }
}

From source file:Main.java

public Main() throws HeadlessException {
    setSize(200, 200);// w  ww.  j ava2s . c  om
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    JLabel usernameLabel = new JLabel("Username: ");
    JTextField usernameTextField = new JTextField();
    usernameTextField.setPreferredSize(new Dimension(100, 20));
    add(usernameLabel);
    add(usernameTextField);

    usernameTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            JTextField textField = (JTextField) e.getSource();
            String text = textField.getText();
            textField.setText(text.toUpperCase());
        }

        public void keyTyped(KeyEvent e) {
        }

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

From source file:net.femtoparsec.jwhois.gui.JWhoIsQueryGUI.java

@Override
public void keyReleased(KeyEvent e) {
    if (e.getSource() == queryField) {
        this.updateButtonState();
    }//from  ww  w  . j a v a 2  s  . c om
}

From source file:com.github.fritaly.dualcommander.TabbedPane.java

@Override
public void keyReleased(KeyEvent e) {
    if (e.getSource() == getSelectedComponent()) {
        // Propagate the event to our listeners
        processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(),
                e.getKeyChar(), e.getKeyLocation()));
    }/*from w  w w  . ja  v a  2  s  .c  o  m*/
}

From source file:com.github.fritaly.dualcommander.TabbedPane.java

@Override
public void keyTyped(KeyEvent e) {
    if (e.getSource() == getSelectedComponent()) {
        // Propagate the event to our listeners
        processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(),
                e.getKeyChar(), e.getKeyLocation()));
    }/*from ww  w  . ja va  2s . co  m*/
}