Home > Java > javaTutorial > body text

Introduction to the method of switching between multiple scenes in javafx (with code)

不言
Release: 2019-03-14 10:52:58
forward
5377 people have browsed it

This article brings you an introduction to the method of switching between multiple scenes in javafx (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

I was working on a javafx application some time ago and encountered some pitfalls. Record it in this article. (If you have a better solution, please comment, I am a novice, light spray)

1. Problem

According to the official Chinese document, a single interface form login was successfully run. So I wanted to try multi-interface jump myself and add event responses to buttons. However, no matter how I operate, I get an error, and Baidu has been trying for a long time without a solution. Later, Google found a suitable solution.

2. Code

The following code is the button to create a string in the fxml file of my main program interface

 <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>
Copy after login

This is what I solved by using the following method to pop up another interface through a button action. Among them, CreateString.fxml is the interface layout of the pop-up window.

 //创建字符串
    @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();
    }
Copy after login

The above is the detailed content of Introduction to the method of switching between multiple scenes in javafx (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!