Add new ListItem to ComboBox
I've got an editable enabled ComboBox where I have to add another ListItem.
I can get the existing ListItems of the ComboBox with
but I cannot set the Property with the opposite:
Has anyone a help or conclusion?
Re: Add new ListItem to ComboBox
In general, it is a bit dangerous to set properties in the software under test. This causes methods to be invoked on internal objects, and you can easily end up with problems that could not be created by a normal user. I strongly encourage you to enter input into a combobox the way a user would, by clicking on it, using keys to select the text and using keys to type in the input.
That said, the JComboBox doesn't really have a text property. RobotJ creates this property for objects that do not really have it. This is why it can be queried but not set.
If you REALLY want to set the text programmatically, you need to ask the combobox for its editor, and set the "item" property on the editor. If you do this, you will have a reference to the editor object, and should "unregister it". The code to set the text to "banana" would look like this:
TestObject editor = (TestObject)myComboBox() .getProperty("editor");