Example usage for javax.accessibility AccessibleState FOCUSED

List of usage examples for javax.accessibility AccessibleState FOCUSED

Introduction

In this page you can find the example usage for javax.accessibility AccessibleState FOCUSED.

Prototype

AccessibleState FOCUSED

To view the source code for javax.accessibility AccessibleState FOCUSED.

Click Source Link

Document

Indicates this object currently has the keyboard focus.

Usage

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);//from ww w .ja v a  2 s .com
                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.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java

private void initDpComboBox() {
    comboBoxDp.addActionListener(new ActionListener() {
        @Override//w  w  w  . java2  s  .  c o  m
        public void actionPerformed(ActionEvent event) {
            model.setDpAndFileName((String) comboBoxDp.getSelectedItem());
            textFieldFileName.setText(model.getFileName());
            showIconPreview();
        }
    });

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

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

private void initColorComboBox() {
    comboBoxColor.addActionListener(new ActionListener() {
        @Override//from   www .  jav  a 2  s .  co  m
        public void actionPerformed(ActionEvent event) {
            model.setColorAndFileName((String) comboBoxColor.getSelectedItem());
            textFieldFileName.setText(model.getFileName());
            showIconPreview();
        }
    });

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