更改可编辑JComboBox中的现有项目

时间:2023-01-27 13:18:44

I want to implement editing of the combo items, e.g. when I select 3-th item "Item 3" and it appears in the input field, I alter the string to "Item 3 new" and press some button. I want 3-d item to have "Item 3 new" text.
Is there any simple solution?

我想实现组合项目的编辑,例如当我选择第3项“项目3”并且它出现在输入字段中时,我将字符串更改为“项目3新”并按下某个按钮。我希望3-d项目有“Item 3 new”文本。有没有简单的解决方案?

1 个解决方案

#1


1  

You have to write an ActionListener that replaces the selected element. As a basis, see Using an Editable Combo Box; the full example is in ComboBoxDemo2.

您必须编写一个ActionListener来替换所选元素。作为基础,请参阅使用可编辑的组合框;完整的示例是在ComboBoxDemo2中。

#1


1  

You have to write an ActionListener that replaces the selected element. As a basis, see Using an Editable Combo Box; the full example is in ComboBoxDemo2.

您必须编写一个ActionListener来替换所选元素。作为基础,请参阅使用可编辑的组合框;完整的示例是在ComboBoxDemo2中。