Question: I want to make a `JComboBox` in which a particular item text should change and becomes editable on selection.For example if `JComboBox` has two items `"ONE","TWO"` in it's list then on Selection of `"TWO"`.

I have wrote a sample program in which either i can make field editable or can change the Text but not both.So someone please suggest how to make selective item editable and changed text as well

```
 Object[] items = new Object[]{"One","Two"};
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel(items);        

    final JComboBox comboBox = new JComboBox(dcbm);
    comboBox.setPreferredSize(new Dimension(200, 20));        
    comboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            Object selectedItem = comboBox.getSelectedItem();
            boolean editable = selectedItem instanceof String && ((String)selectedItem).equals("Two");
             comboBox.setEditable(editable);
             //comboBox.setSelectedItem("text has changed");

        }
    });

```

Answer: 
Something like...

```
String[] data = {"One", "Two"};
JComboBox<String> cb = new JComboBox<>(data);
add(cb);

cb.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        cb.setEditable(cb.getSelectedIndex() != 0);
    }
});

```

will basically do it, but what it won't do, is update the value of the model, just so you know ;)

If you want to make the editor "blank" when the combobox becomes editable, you could add...

```
if (cb.isEditable() && cb.getSelectedIndex() != -1) {
    cb.setSelectedItem("");
}

```

to the `ActionListener`
So I'm not the best with jComboBox off the top of my head so this may not help but I would assume it uses an array to set the strings for the objects in the combo box along the lines of 

```
(new String[] {"ONE","TWO"});

```

and with my understanding of arrays you could do something like 

```
comboBox.addMouseListener(new MouseAdapter(){
    public void ActionPerformed(MouseEvent click){
        optionTwoClicked(click);
    }
}

```

and then add the handler with something like 

```
private void optionTwoClicked(MouseEvent click){
    if (click.getSelectedItem()=String[2]){
        String onTwo = JOptionPane.showInputDialog(null,"Enter your message","Messages",2);
        textItem.setText()="onTwo";
    }else{ //do something here?
    }
}

```

Like I said before, not absolutely familiar with jComboBox, but,
Hope that helps!