preface

Recently in learning SpringBoot and javaFX, ready to do a small project practice hand, this article records the use of SpringBoot development javaFX environment configuration.

To prepare

  • IDEA
  • JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX: JavaFX
  • Deployment headaches library:

    Gluonhq.com/products/ja…

  • JavaFX Scene Builder 2.0(Visualization tool to speed up JavaFX graphical interface development,Installation is strongly recommended)

    Deployment headaches Scene Builder 2.0

steps

1. Create a SpringBoot application





And then… The default line

Complete:

Adjust the directory

Here I set SRC as the source folder and create the View and Controller packages

2. Configure JavaFX Scene Builder 2.0

File > Settings > Languages and Frameworks >javaFX

Fill in your installation path:

3.Maven dependency introduction

Pom.xml recommends a site to check on the latest Maven :mvnrepository.com/

<? The XML version = "1.0" encoding = "utf-8"? > < project XMLNS = "http://maven.apache.org/POM/4.0.0" XMLNS: xsi = "http://www.w3.org/2001/XMLSchema-instance" Xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion > 4.0.0 < / modelVersion > < the parent > < groupId > org. Springframework. Boot < / groupId > The < artifactId > spring - the boot - starter - parent < / artifactId > < version > against 2.4.1 < / version > < relativePath / > < / parent > < the groupId > com. Rightstar < / groupId > < artifactId > deployment headaches < / artifactId > < version > 0.0.1 - the SNAPSHOT < / version > < name > deployment headaches < / name > <description>Demo project for Spring Boot</description> <properties> <java.version>12</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>de.roskenet</groupId> <artifactId>springboot-javafx-support</artifactId> < version > 2.1.6 < / version > < / dependency > < the dependency > < groupId > org. Openjfx < / groupId > <artifactId>javafx-controls</artifactId> <version>16-ea+5</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-base</artifactId> <version>16-ea+5</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-fxml</artifactId> <version>16-ea+5</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-graphics</artifactId> <version>16-ea+5</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-web</artifactId>  <version>16-ea+5</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-swing</artifactId> <version>16-ea+5</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-media</artifactId> <version>16-ea+5</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.4.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>Copy the code

4. Write your first interface

  • Write initScene.fxml with SceneBuilder

    Create initscene. FXML in the resource folder and open it

  • Add a Pane and Button



    CTRL + s to save

  • Write the bound InitSceneView class (inheritanceAbstractFxmlView)

package com.rightstar.view;

import de.felixroske.jfxsupport.AbstractFxmlView;
import de.felixroske.jfxsupport.FXMLView;

@FXMLView("/InitScene.fxml")
public class InitSceneView extends AbstractFxmlView {

}

Copy the code
  • Write the startup class JavafxApplication(inheritanceAbstractJavaFxApplicationSupport)

package com.rightstar; import com.rightstar.view.InitSceneView; import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class JavafxApplication extends AbstractJavaFxApplicationSupport { public static void main(String[] args) { launch(JavafxApplication.class, InitSceneView.class,args); }}Copy the code
  • Start (emphasis on configuring VM)



— Module-path instead of the javaFXSDK path you installed (example):

- the module - the path D: \ "javaTools \ deployment headaches - SDK - 11.0.2 \ lib" -- add - modules = deployment headaches. Controls, deployment headaches. FXMLCopy the code
  • Start the

  • ok

After the speech

How to use SpringBoot+javaFX to write a simple file tree display program