Javafx 2 JavaFX2-多个选项卡窗格
我想这样做: 在左边的atm机上,我在根控制器中有一个列表视图Javafx 2 JavaFX2-多个选项卡窗格,javafx-2,Javafx 2,我想这样做: 在左边的atm机上,我在根控制器中有一个列表视图 @FXML ListView<String> listView; 在start方法中,我调用initRootLayout方法 void initRootLayout() { FXMLLoader fxmlLoader = new FXMLLoader(MainDo.class.getResource("view/RootLayout.fxml")); try { rootLayou
@FXML
ListView<String> listView;
在start方法中,我调用initRootLayout方法
void initRootLayout() {
FXMLLoader fxmlLoader = new FXMLLoader(MainDo.class.getResource("view/RootLayout.fxml"));
try {
rootLayout = fxmlLoader.load(); // rootLayout == BorderPane
Scene scene = new Scene(rootLayout);
RootController rootController = fxmlLoader.getController();
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
我的问题:
谢谢当我第一次尝试JavaFX时,这对我帮助很大。它显示了在屏幕之间转换的一种非常简单的方法。一旦掌握了这一点,您就会看到许多限制,现在是时候转向像Adam Bein那样的依赖注入框架了。这功能强大得多,一旦你习惯了这些约定,就很容易实现。关于你的列表项,我看不到你在代码的
列表视图中加载这些项的位置,因此很难确定你的问题。在调用initRootLayout()
之前,我怀疑您正在使用listView=new listView()
实例化它,然后当您调用fxmloader.load()
时,它正在重新实例化它,导致更改丢失。您应该在调用fxmloader.load()
后添加项目。
listView.setItems(names);
void initRootLayout() {
FXMLLoader fxmlLoader = new FXMLLoader(MainDo.class.getResource("view/RootLayout.fxml"));
try {
rootLayout = fxmlLoader.load(); // rootLayout == BorderPane
Scene scene = new Scene(rootLayout);
RootController rootController = fxmlLoader.getController();
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}