Issue
ComboBox
and CheckBox
set element's inside it https://ibb.co/7YWQfLh, but don't display this element's https://ibb.co/Mfy2mZb
I create boxes in different panes (HBox
, VBox
, AnchorPane
, GridPane
), result the same.
I used Enum and usual String and result the same.
public class TestFXController {
@FXML
private ComboBox<String> asd;
@FXML
private ChoiceBox<String> fgh;
@FXML
void initialize() {
ObservableList<String> langs =
FXCollections.observableArrayList("Java", "JavaScript", "C#", "Python");
asd = new ComboBox<>(langs);
fgh = new ChoiceBox<>(langs);
}
}
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="- Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="TestFXController">
<children>
<ComboBox fx:id="asd" prefWidth="150.0" />
<ChoiceBox fx:id="fgh" layoutX="14.0" layoutY="70.0" prefWidth="150.0" />
</children>
</AnchorPane>
What's wrong. I want this result.
https://metanit.com/java/javafx/pics/4.16.png
Solution
Your Combo box and Choice box already exists as long as they have to correct fx:ids set in your FXML (asd, and fgh), so you don't need the following:
asd = new ComboBox<>(langs);
fgh = new ChoiceBox<>(langs);
From your initialize method you can for example set your items in the combo box like this:
ObservableList<String> langs = FXCollections.observableArrayList("Java", "JavaScript", "C#", "Python");
asd.setItems(langs);
That should work fine, it does for me as you can see in the image below, as long as you've got the correct fx:id set (which you look to have).
Hope it helps :)
Answered By - Robert
Answer Checked By - Mildred Charles (JavaFixing Admin)