Code example for JTextComponent

Methods: addKeyListenersetDocument

0
 
    public S11InitialSelection(final JComboBox comboBox) {
        this.comboBox = comboBox;
        model = comboBox.getModel();
        editor = (JTextComponent) comboBox.getEditor().getEditorComponent();
        editor.setDocument(this);
        comboBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (!selecting) highlightCompletedText(0);
            } 
        }); 
        editor.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                if (comboBox.isDisplayable()) comboBox.setPopupVisible(true);
            } 
        }); 
        // Handle initially selected object 
        Object selected = comboBox.getSelectedItem();
        if (selected!=null) setText(selected.toString()); 
        highlightCompletedText(0); 
Experience pair programming with AI  Get Codota for Java