如何使用 JavaFX 建立超連結?


超連結是一種 UI 元件,對點選和滾動做出響應。你可以透過例項化 javafx.scene.control.Hyperlink 類 來建立超連結。

示例

以下示例演示瞭如何建立 **超連結**。

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) {
      //Creating a hyper link
      Hyperlink link = new Hyperlink("https://tutorialspoint.tw");
      //Creating a vbox to hold the pagination
      VBox vbox = new VBox();
      vbox.setSpacing(5);
      vbox.setPadding(new Insets(50, 50, 50, 60));
      vbox.getChildren().addAll(link);
      //Setting the stage
      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);
   }
}

更新於:2020-05-18

339 次瀏覽

開啟你的 職業生涯

完成課程取得認證

開始
廣告