有没有办法从FXML控制器获得舞台? [英] Is there a way to get the stage from from a FXML controller?

查看:167
本文介绍了有没有办法从FXML控制器获得舞台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口,有2个场景,我需要在单击按钮之间进行更改。我在试图想办法从FXML文档的控制器中有效地改变场景时遇到了问题。是否有一种方法可以使用javafx这样做,例如this.getScene()。getStage()或其他类似的东西?

I have a window that has 2 scenes that i need to change between when i click a button. I am having issues trying to think of ways to efficiently change scenes from the controller for the FXML document. Is there a method to do this with javafx like this.getScene().getStage() or something along those lines?

推荐答案

您的控制器很可能访问您可以执行的节点(例如按钮)

Your controller has most likely access to a Node (eg Button) the you can do

@FXML
Button b;
...
@FXML
public void flip() {
  Stage s = (Stage)b.getScene().getWindow();
}

这篇关于有没有办法从FXML控制器获得舞台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆