Yes, you can add/remove items at any moment using getItems()
comboBox1.getItems().add("Beer");
comboBox1.getItems().add("Whiskey");
comboBox1.getItems().add("Water");
or directly updating list:
options1.add("Milk");
質問
I need to know whether it is possible to add values to a ComboBox at different times.
ObservableList<String> options1
= FXCollections.observableArrayList(
"Civil (CE)", "Computer (CT)", "Electrical (EEE)", "Electronics (ELS)",
"Mechanical (ME)");
comboBox1 = new ComboBox(options1);
comboBox1.setPrefSize(280, 30);
This is my code of ComboBox. In it I added 5 values at a time. But is it possible to add each value at different times, for example, add values one by one in a while loop. I tried it and the result was that each value overlapped previously added values, and as a result only one value was present in the ComboBox at the end. This the code with while loop -
while (rs.next()) {
subject = rs.getString("subname");
ObservableList<String> options1 = FXCollections.observableArrayList(subject);
comboBox1 = new ComboBox(options1);
}
Can I add values to ComboBox at different times, one after another, without overlapping the previous value ?
解決
Yes, you can add/remove items at any moment using getItems()
comboBox1.getItems().add("Beer");
comboBox1.getItems().add("Whiskey");
comboBox1.getItems().add("Water");
or directly updating list:
options1.add("Milk");