JDK11 在 IDEA 中配置 JavaFX

5 篇文章 0 订阅

安装Java 和 JavaFX 不多说了。

新建项目

pom.xml 文件

<properties>
	<java.version>11</java.version>
	<maven.compiler.source>11</maven.compiler.source>
	<maven.compiler.target>11</maven.compiler.target>
	<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>

<dependencies>
	<dependency>
		<groupId>org.openjfx</groupId>
		<artifactId>javafx-controls</artifactId>
		<version>11</version>
	</dependency>
	<dependency>
		<groupId>org.openjfx</groupId>
		<artifactId>javafx-fxml</artifactId>
		<version>11</version>
	</dependency>
</dependencies>

<build>
	<plugins>
		<plugin>
			<groupId>org.openjfx</groupId>
			<artifactId>javafx-maven-plugin</artifactId>
			<version>0.0.4</version>
			<configuration>
				<mainClass>test.Test</mainClass>
			</configuration>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.8.1</version>
			<configuration>
				<source>${java.version}</source>
				<target>${java.version}</target>
			</configuration>
		</plugin>
	</plugins>
</build>

在 java 根目录 创建 module-info.java 文件

module my.javafx {
    requires javafx.controls;
    requires javafx.fxml;
    
    exports test;
}

Test.java 文件

package test;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * Test
 * 
 * @date 2020-05-25 17:59
 */
public class Test extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        System.out.println("Hello");
        AnchorPane root = new AnchorPane();
        root.getChildren().add(new Button("test"));
        stage.setScene(new Scene(root));
        stage.setWidth(200);
        stage.setHeight(200);
        stage.show();
    }
}

看看效果

 

注意事项

如果运行:mvn clean javafx:run 报错,看看JAVA_HOME是否配置的java11

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值