×

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

Related Topics

JavaFX HBox

In the JavaFX application, in order to set HBox as a layout, the HBox class is used. The HBox layout allows us to arrange the components in one row. All...

3 minutes read.

JavaFX Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 minutes read.

JavaFX Bar Chart

In the JavaFX application, in order to create Bar Chart, the BarChart class is used. The Bar Chart allows us to plot data along different bars to show the scales...

4 minutes read.

JavaFX Reflection

In the JavaFX application, in order to apply various reflection effect, we use this class. It has the ability to create the reflection of the given object. This effect adds...

4 minutes read.

JavaFX StackPane

In the JavaFX application, in order to set Stack Pane as a layout, the StackPane class is used. The StackPane layout allows us to arrange the components in the stack...

4 minutes read.

JavaFX Arc

In the JavaFX application, in order to draw an arc, the Arc class is used. The Arc allows us to join any points in the space. All methods needed for...

5 minutes read.

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

4 minutes read.

JavaFX TilePane

In the JavaFX application, in order to set TilePane as a layout, the TilePane class is used. The TilePane layout allows us to arrange the components in the same sized...

4 minutes read.

JavaFX Rotate Transition

In the JavaFX application, in order to generate the rotate transition, we have to apply rotation transition on any particular shape. It has the ability to rotate the shape along...

4 minutes read.

JavaFX Shadow

In the JavaFX application, in order to apply various Shadow effect from a single source, we use this class. It has the ability to create the shadow of the given...

3 minutes read.

JavaFX Scaling

In the JavaFX application, in order to apply various Scaling effects, we use this class. It has the ability to change the size of the given object. All methods needed...

5 minutes read.

JavaFX Fill Transition

In the JavaFX application, in order to generate the fill transition, we have to apply fill transition on any particular shape. It has the ability to fill the given shape...

4 minutes read.

JavaFX Parallel Transition

In the JavaFX application, in order to generate the parallel transition, we have to apply parallel transition on any particular shape. It has the ability to execute multiple transactions parallelly....

4 minutes read.

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine. Prerequisite: Operating systemAny Operating system (Windows, Linux, Mac)Memory requirementNo minimum requirementDisk SpaceNo minimum requirementJDK versionJDK...

3 minutes read.

JavaFX Stroke Transition

In the JavaFX application, in order to generate the stroke transition, we have to apply stroke transition on any particular shape. It has the ability to give different color strokes...

4 minutes read.

JavaFX Box

In the JavaFX application, in order to draw a Box, the Box class is used. The Box allows us to form 3D shape having rectangular faces. All methods needed for...

4 minutes read.

JavaFX Architecture

JavaFX architecture consists of many built-in components such as JavaFX public API, Scene Graph, Quantum Toolkit, Prism, Glass windowing toolkit, web view, media engines. These components help to develop rich...

3 minutes read.

JavaFX Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX Scale Transition

In the JavaFX application, in order to generate the scale transition, we have to apply scale transition on any particular shape. It has the ability to scale the shape along...

4 minutes read.