JavaFX Hyperlink create

Description

JavaFX Hyperlink create

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Main extends Application {

   public static void main(String[] args) {
      Application.launch(args);/*from  w  w w.ja  v  a  2s  .  com*/
   }

   @Override
   public void start(Stage primaryStage) {
      primaryStage.setTitle("java2s.com");
      Group root = new Group();
      Scene scene = new Scene(root, 300, 250, Color.WHITE);

      HBox rowBox = new HBox(20);
      final Hyperlink jfxHyperLink = new Hyperlink("https://www.demo2s.com");
      jfxHyperLink.setUserData("https://www.demo2s.com");
      
      jfxHyperLink.setOnAction(new EventHandler<ActionEvent>() {
         public void handle(ActionEvent evt) {
            System.out.println("clicked");
         }
      });
      rowBox.getChildren().add(jfxHyperLink);

      root.getChildren().add(rowBox);

      primaryStage.setScene(scene);

      primaryStage.show();
   }
}



PreviousNext

Related