JavaFX Tutorial Index

JavaFX Tutorial JavaFX Installation JavaFX Application Structure JavaFX Architecture

JavaFX Applications Charts

JavaFX Bar Chart JavaFX Bubble Chart JavaFX Pie Chart JavaFX Scatter Chart JavaFX Area Chart JavaFX Line Chart

JavaFX 2D Shapes

JavaFX Arc JavaFX Circle JavaFX Ellipse JavaFX Line JavaFX Polygon JavaFX Rectangle JavaFX Color JavaFX Gradient Color

JavaFX 3D Shapes

JavaFX Box JavaFX Cylinder JavaFX Sphere

JavaFX Animations

JavaFX Rotate Transition JavaFX Translate Transition JavaFX Fade Transition JavaFX Fill Transition JavaFX Parallel Transition JavaFX Path Transition JavaFX Pause Transition JavaFX Scale Transition JavaFX Sequential Transition JavaFX Stroke Transition

JavaFX CSS

JavaFX ID Selector JavaFX Inline Styles JavaFX Selectors

JavaFX Effect

JavaFX Blend JavaFX Bloom JavaFX Color Adjust JavaFX Color Input JavaFX Drop Shadow JavaFX Gaussian Blur JavaFX Glow JavaFX Image Input JavaFX Inner Shadow JavaFX Light Distant JavaFX Light Point JavaFX Light Spot JavaFX Lighting JavaFX Motion Blur JavaFX Reflection JavaFX Shadow

JavaFX Layouts

JavaFX Layouts JavaFX BorderPane JavaFX GridPane JavaFX StackPane JavaFX HBox JavaFX TilePane

JavaFX Event Handling

JavaFX Event Handling JavaFX Event Filters JavaFX Convenience Methods

JavaFX Transformation

JavaFX Transformation JavaFX Scaling JavaFX Rotation JavaFX Translation JavaFX Shear

JavaFX UI

JavaFX Menu JavaFX Button JavaFX Button Styling JavaFX CheckBox JavaFX File Chooser JavaFX HyperLink JavaFX Label JavaFX UI Controls JavaFX PasswordField JavaFX ProgressBar JavaFX RadioButton JavaFX ScrollBar JavaFX Slider JavaFX TextField

JavaFX HyperLink

In the JavaFX application, in order to access and use webpages, hyperlinks are used. In HTML anchor tags are used in the same way in JavaFX hyperlinks are used. To use hyperlinks in JavaFX, javafx.scene.control.HyperLink class is used. All the necessary methods required for dealing with a hyperlink are available in JavaFX.  

JavaFX HyperLink:

Example:

import javafx.application.Application;  
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;  


  
public class HyperLinkUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
        Hyperlink hpl = new Hyperlink("https://www.wikipedia.org");  
        StackPane pane = new StackPane();  
        pane.getChildren().add(hpl);  
        Scene scn=new Scene(pane,600,400);  
        primaryStage.setScene(scn);  
        primaryStage.setTitle(" JavaFX Hyperlink Example");  
        primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the HyperLink in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.HyperLink, javafx.scene.layout.StackPane.

Then we have created one class named HyperLinkUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold hyperlink, a StackPane object is created which is then passed to the Scene class object.

The HyperLink is created with its constructor having a link passed in it.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, launch(args) method is called in the main() method. In output Frame like container is displayed with the title, “ JavaFX HyperLink Example ”. Also, it displays HyperLink for the Wikipedia website.

JavaFX HyperLink

JavaFX HyperLink Action:

Example:

import javafx.application.Application;  
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;  


  
public class HyperLinkUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    Hyperlink hpl = new Hyperlink("http://www.google.com");  
        StackPane pane = new StackPane();  
        hpl.setOnAction(e -> System.out.println(" Google Chrome link is Clicked by the user "));  
        pane.getChildren().add(hpl);  
        Scene scn=new Scene(pane,600,400);  
        primaryStage.setScene(scn);  
        primaryStage.setTitle(" JavaFX Hyperlink Example");  
        primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the HyperLink and action on it in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.HyperLink, javafx.scene.layout.StackPane.

Then we have created one class named HyperLinkUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold HyperLink, a StackPane object is created which is then passed to the Scene class object.

The HyperLink is created with its constructor and link passed in it. Also, the action is set on it using the setOnAction() method which will show the Google Chrome link is Clicked by the user when the www.google.com link in the container is clicked.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, "JavaFX Hyperlink Example ”. Also, it displays HyperLink for google. After clicking on that HyperLink the output is displayed in the console saying the Google Chrome link is Clicked by the user.

JavaFX HyperLink

JavaFX Graphics HyperLink :

Example:

import java.io.FileInputStream;
import javafx.application.Application;  
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;  


  
public class HyperLinkUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    Hyperlink hpl = new Hyperlink();  
        hpl.setOnAction(e -> System.out.println("Hyperlink with Home icon clicked"));  
        FileInputStream file = new FileInputStream("home.jpg");  
        Image newimg = new Image(file);  
        ImageView newview=new ImageView(newimg);  
        hpl.setGraphic(newview);  
        StackPane pane = new StackPane();  
        pane.getChildren().add(hpl);  
        Scene scene = new Scene(pane,600,400);  
        primaryStage.setScene(scene);  
        primaryStage.setTitle("JavaFx Icon Hyperlink Example");  
        primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the Graphics HyperLink and action on it in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.HyperLink, javafx.scene.layout.StackPane, java.io.FileInputStream, import javafx.scene.image.Image, and javafx.scene.image.ImageView.

Then we have created one class named HyperLinkUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold HyperLink with Home Icon, a StackPane object is created which is then passed to the Scene class object.

The HyperLink is created with its constructor. Also, the action is set on it using the setOnAction() method which will show Hyperlink with Home icon clicked, when Home Icon link in the container is clicked.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, "JavaFX Icon Hyperlink Example ”. Also, it displays HyperLink with Home Icon. After clicking on that HyperLink the output is displayed in the console saying Hyperlink with Home icon clicked.

JavaFX HyperLink