我需要在javafx中创建后退按钮功能吗? [英] I need to create a back button functionality in javafx?
问题描述
我目前正在使用类似这样的代码将此代码绑定到fxml javafx按钮
I am presently using something like this binding this code to fxml javafx button
Parent parent = FXMLLoader.load(getClass().getResource("AolRun.fxml"));
Stage stage = new Stage();
stage.initStyle(StageStyle.UTILITY);
stage = (Stage) run.getScene().getWindow();
Scene scene = new Scene(parent);
stage.setScene(scene);
scene.getStylesheets().add("/css/Style.css");
stage.setTitle("Output");
stage.setResizable(false);
stage.show();
是否有一个我们可以用于背面的通用函数,它只是将屏幕从当前的fxml场景转换为下一个fxml。
Is there a generic function we can use for back which just transits screen from the present fxml scene to the next fxml .
我为每个fxml都有单独的场景。
I have separate scene for every fxml.
推荐答案
1)更好的方法是更改父布局并仅使用一个场景。
1)A better approach is to change the parent layout and use only one Scene.
2)虽然您可以使用按钮
。当触发 onAction
方法时,您选择要进入的场景
。您可以将场景存储在数组中并移动到下一个或上一个索引,或者实现您自己的逻辑,其中场景
将跟随或哪个场景是当前的场景场景。
2)Although you can have the functionality you want using a Button
.When the onAction
method is fired you choose in what Scene
to go.You can either have the Scenes stored in the array and move to the next or previous index, or implement your own logic which Scene
will follow or which Scene is the previous of the current Scene.
这里是1更有用的地方,因为你可以使用Animation转到下一个或上一个场景。例如 TransitionAnimation
。
Here is where the 1 is more usefull cause you can go to the next or previous "Scene" using an Animation.For example TransitionAnimation
.
~~>除了下面的评论
~~> In addition to the comments below
如果您想知道在使用ObservableList或Array之前用户是哪个场景。
If you want to know in which Scene was the user before you can use an ObservableList or Array.
每次都是用户更改场景,前一个场景存储在数组中。
Everytime the user changes Scene ,the previous Scene is stored in the array.
这篇关于我需要在javafx中创建后退按钮功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!