Search in sources :

Example 11 with PopupMenuListener

use of javax.swing.event.PopupMenuListener in project knime-core by knime.

the class SQLTypeCellEditor method initializeComboBox.

/**
 * Initializes the underlying JComboBox used as cell editor
 *
 * @param comboBox
 */
private void initializeComboBox(final JComboBox<String> comboBox) {
    comboBox.setEditable(true);
    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ev) {
            if (ev.getActionCommand().equals("comboBoxEdited")) {
                String elem = ((String) comboBox.getEditor().getItem()).trim();
                m_table.setValueAt(elem, m_row, m_col);
                addElement(m_relatedKey.toString(), elem);
            }
        }
    });
    comboBox.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
            comboBox.getEditor().getEditorComponent().setEnabled(false);
        }

        @Override
        public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
            comboBox.getEditor().getEditorComponent().setEnabled(true);
        }

        @Override
        public void popupMenuCanceled(final PopupMenuEvent e) {
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) PopupMenuEvent(javax.swing.event.PopupMenuEvent)

Aggregations

PopupMenuEvent (javax.swing.event.PopupMenuEvent)11 PopupMenuListener (javax.swing.event.PopupMenuListener)11 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 List (java.util.List)3 JPopupMenu (javax.swing.JPopupMenu)3 JComponent (javax.swing.JComponent)2 JMenuItem (javax.swing.JMenuItem)2 Ref (com.intellij.openapi.util.Ref)1 SingleRowPassInfo (com.intellij.ui.tabs.impl.singleRow.SingleRowPassInfo)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 GridLayout (java.awt.GridLayout)1 FocusAdapter (java.awt.event.FocusAdapter)1 FocusEvent (java.awt.event.FocusEvent)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 KeyEvent (java.awt.event.KeyEvent)1 MouseEvent (java.awt.event.MouseEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1