我创建了一个 tabPane。在每个选项卡下,我都包含 () 一个 fxml 来显示实际的会话用户,代码如下:
home-tab.fxml 有这一行:
<fx:include fx:id="topTab" source="../top-tab.fxml"/>
顶部tab.fxml:
<AnchorPane maxHeight="20.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="wuendo.client.TopTabController">
<children>
<HBox id="hbox_top" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<Label id="label_session" prefHeight="20.0" text="SESSION : " />
<Label fx:id="sessionLabel" prefHeight="20.0" text="" />
</HBox>
</children>
</AnchorPane>
TopTabController.java:
@FXML public Label sessionLabel;
HomeTabController.java:
@FXML private TopTabController topTabController;
@Override
public void initialize(URL url, ResourceBundle rb) {
URL location = getClass().getResource("../top-tab.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
AnchorPane root = null;
try {
root = (AnchorPane) fxmlLoader.load();
} catch (IOException ex) {
Logger.getLogger(HomeTabController.class.getName()).log(Level.SEVERE, null, ex);
}
topTabController = (TopTabController) fxmlLoader.getController();
Label txt = (Label) root.lookup("#sessionLabel");
txt.setText("blabla");
System.out.println("sessionLabel= " + topTabController.sessionLabel.getText());
}
当我执行此操作时,控制台打印“blabla”,但程序中未修改标签(gui)
我必须做什么才能看到更新的值?
谢谢你们