【发布时间】:2014-09-30 21:48:18
【问题描述】:
在我的应用程序中,我将用户名从登录场景传递到主场景。信息成功传递,但未显示在 gui 中。 在切换场景之前,我这样做是为了将用户名传递给主控制器:
try
{
URL location = getClass().getResource("Main.fxml");
FXMLLoader fxmlLoader = new FXMLLoader();
Parent root = (Parent) fxmlLoader.load(location.openStream());
LogInController ctrl = fxmlLoader.getController();
ctrl.setUserDetails(userName);
}
catch (IOException ex)
{
Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
}
主控制器中的 setUserDetails 方法:
void setUserDetails(String userName)
{
System.out.println(userName); //working
nameLabel.setText(userName); //do nothing !!
}
然后我显示主要场景.. 该名称打印在控制台中,但不显示在 gui 中。我应该怎么办?我需要重新绘制或刷新场景吗?如果是,那我该怎么做? TNX
【问题讨论】:
-
rest of the code in your controller and fxml 是什么?您是否(错误地)写了@FXML nameLabel = new Label()之类的东西?
-
不,我没有.. 其余的代码很大:(
-
你应该阅读我提供的 mcve 链接并想出一个。
标签: user-interface javafx