测试环境:
- Centos 8
- jdk14
- javaFX15
- List item
先从官网下载JavaFX 15
地址为https://gluonhq.com/products/javafx/
我这里选的是JavaFX Linux SDK
创建Java项目
- Ctrl+Shift+p create java project
- no building tools
- 输入项目名
导入lib
- unzip javafx-sdk-15. 0. 1
- cp javafx-sdk-15. 0.1/lib/* ./lib复制javafx-sdk-15.0.1/lib下的所有文件到项目lib下
- vscode中右键lib目录 Add Folder to Java Source Path
创建测试文件
src/App.java
public class App {
public static void main(String[] args) throws Exception {
MainApp.main(args);
}
}
src/MainApp.java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MainApp extends Application {
/*
* The main() method is ignored in correctly deployed JavaFX application. main()
* serves only as fallback in case the application can not be launched through
* deployment artifacts, e.g., in IDEs with limited FX support. NetBeans ignores
* main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
// new Label
Label label = new Label("Hello World!");
// create a top pane
StackPane root = new StackPane();
// scene
Scene scene = new Scene(root, 600, 350);
root.getChildren().add(label);
stage.setScene(scene);
stage.setTitle("javaFX");
stage.show();
}
}
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch App",
"request": "launch",
"mainClass": "App"
}
]
}
需要scene builder可以在甲骨文公司下载到。