您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

javafx中多场景的切换的方法介绍(附代码)

2026/2/6 16:30:00发布9次查看
本篇文章给大家带来的内容是关于javafx中多场景的切换的方法介绍(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
前段时间在做javafx的应用程序,遇到一些坑。以本文记录之。(如有更好的解决办法欢迎评论,本人小白,轻喷)
1.问题
按照官方的中文文档,成功的运行了单一界面的表单登录。于是想自己试试多界面跳转,给按钮添加事件响应。可是怎么操作都报错,百度了许久没有解决办法。后来google后找到了一个合适的解决办法。
2.代码
下面一段代码是我主程序界面fxml文件中,创建字符串的按钮
<button fx:id="createstring" defaultbutton="true" layoutx="216.0" layouty="159.0" mnemonicparsing="false" onaction="#createstringoperation" prefheight="58.0" prefwidth="154.0" text="创建字符串"> <font> <font size="23.0" /> </font> </button>
这是我通过下面方法解决的通过一个按钮动作弹出另一个界面。其中createstring.fxml是弹出窗口的界面布局。
//创建字符串 @fxml protected void createstringoperation(actionevent event) throws ioexception { parent operation_parent = fxmlloader.load(getclass().getresource("createstring.fxml")); scene operation_creating_scene = new scene(operation_parent); stage createoperation_stage = (stage) ((node) event.getsource()).getscene().getwindow(); createoperation_stage.hide(); createoperation_stage.setscene(operation_creating_scene); createoperation_stage.show(); }
以上就是javafx中多场景的切换的方法介绍(附代码)的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product