Set graphic image for Hyperlink : Hyperlink « JavaFX « Java






Set graphic image for Hyperlink

 
import java.io.File;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
 
public class Main extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("HTML");
        stage.setWidth(500);
        stage.setHeight(500);
        Scene scene = new Scene(new Group());
        VBox root = new VBox();    

        Hyperlink hpl = new Hyperlink("java2s.com");
        
   
        Image image1 = new Image(new File("a.jpg").toURI().toString(), 0, 100, false, false);
        hpl.setFont(Font.font("Arial", 14));
        hpl.setGraphic(new ImageView (image1));
        root.getChildren().addAll(hpl);
        
        scene.setRoot(root);
 
        stage.setScene(scene);
        stage.show();
    }
 
    public static void main(String[] args) {
        launch(args);
    }
}

   
  








Related examples in the same category

1.Hyperlink as a Button
2.Change font for Hyperlink