【问题标题】:JAVAFX pass information from one scene to another not displayed in the guiJAVAFX 将信息从一个场景传递到另一个场景,但未在 gui 中显示
【发布时间】: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

【问题讨论】:

标签: user-interface javafx


【解决方案1】:

问题解决了!我不知道我需要将场景的根设置为使用 fxmlLoader.load() 创建的父级。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多