【问题标题】:JavaFX stage issue with hide and show AskJavaFX 舞台问题与隐藏和显示问
【发布时间】:2018-12-07 06:25:52
【问题描述】:

我刚开始使用 javafx,单击按钮并打开新阶段时无法隐藏上一个阶段。这是我的代码

也指导我用javafx开发软件更好

public void login(ActionEvent event) throws Exception
{
    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn=DriverManager.getConnection("jdbc:sqlserver://localhost\\sqlexpress"+";databaseName=itapplication",usernametxt.getText(),passwordtxt.getText());
    Parent mainp = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
    mainpage(mainp);
    }catch (Exception e)
    {
        statuslbl.setText(e.getMessage());

    }

}
public void mainpage(Parent root) throws Exception
{
    Scene scene = new Scene(root);
    //Stage stage = new Stage();
    stage.setScene(scene);
    stage.setTitle("IT APPLICATION");
    stage.show();
}

public void addasset(ActionEvent event) throws Exception
{
    try {

        Parent asset = FXMLLoader.load(getClass().getResource("/application/Addasset.fxml"));
        mainpage(asset);
        /*Scene scene = new Scene(asset);
        addasset.setScene(scene);
        addasset.setTitle("IT APPLICATION");
        addasset.show();*/
        }catch(Exception e)
        {
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error");
            alert.setHeaderText(null);
            alert.setContentText(e.toString());
        }
}

}

【问题讨论】:

    标签: javafx


    【解决方案1】:
    Stage anyName= (Stage) (element of the stage you want to hide).getScene().getWindow();
    anyName.hide();
    

    您可以在显示新阶段后立即调用它。 如果您想了解更多,请添加评论。

    【讨论】:

      猜你喜欢
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多