7
我有一個值列表,我想在javaFx的組合框中填充值。這是我的combo.xml如何在JavaFx中將列表值填充到組合框
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="- Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
<ComboBox id="comboId" layoutX="210.0" layoutY="108.0" prefHeight="27.0" prefWidth="102.0" promptText="Select">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Item 1" />
<String fx:value="Item 2" />
<String fx:value="Item 3" />
</FXCollections>
</items>
</Com boBox>
</children>
</AnchorPane>
這是我的主要
public class JavaFXExperiment extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("combo.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
final ComboBox comboId = new ComboBox();
comboId.getItems().addAll(
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]");
}
public static void main(String[] args) {
launch(args);
}
}
這是我的XML文件和主類我想顯示在combobox.anyone這些值,請幫助
謝謝,這打開一個新窗口時也適用。 – lmiguelvargasf
'@FXML public ComboBox myCombobox;' – saikosen