javafx-无法添加项目的ListView
问题描述:
有我FXML文件:javafx-无法添加项目的ListView
<AnchorPane fx:id="anch" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ListView fx:id="list" layoutX="200.0" layoutY="7.0" prefHeight="393.0" prefWidth="200.0" />
</children>
</AnchorPane>
和controllerfile:
@FXML
private ListView<String> list;
@FXML
private AnchorPane anch;
ObservableList<String> li = FXCollections.observableArrayList("red","blue","yellow");
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
list.setItems(li);
}
当我运行该程序的程序,那只能说明空列表。
答
小姐fx:controller
在FXML
例:
<AnchorPane id="AnchorPane" prefHeight="380.0" prefWidth="387.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="PackageName.ControllerFileName">
@manpreetsinghwadhoun如果答案为你工作和似乎没有成为一个问题,质量或类似的东西,考虑接受答案。 – fabian
是啊..工作 –