如何使用 JavaFX 创建超链接?
javafxobject oriented programmingprogramming更新于 2026/1/7 15:08:17
超链接是响应点击和滚动的 UI 组件。您可以通过实例化 javafx.scene.control.Hiperlink 类来创建超链接。
示例
以下示例演示了如何创建 超链接。
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class HiperlinkExample extends Application {
public void start(Stage stage) {
//创建超链接
Hyperlink link = new Hyperlink("https://www.tutorialspoint.com");
//创建 vbox 来容纳分页
VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(50, 50, 50, 60));
vbox.getChildren().addAll(link);
//设置舞台
Group root = new Group(vbox);
Scene scene = new Scene(root, 595, 200, Color.BEIGE);
stage.setTitle("Hyperlink");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}

