×

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 Gradient Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the gradient colors in these shapes using the...

7 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 Pause Transition

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

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 Button Styling

 In the JavaFX application, we can apply CSS styling to buttons in various ways. We can change the size of the button as well as border colour, text colour can...

3 minutes read.

JavaFX Tutorial

Introduction of JavaFX: The most popular applications called Rich Internet Application are build using the JavaFX. This application can run across many platforms. Various devices such as mobile, computers, and tablets...

4 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX Label

The UI Control Label in a JavaFX is used to display the simple text. To use Label in JavaFX application javafx.scene.control.The label class is used. We can place Labels on...

3 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 Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX Button

The button is one of the UI control present in the JavaFX. The javafx.scene.control.Button class is used for creating a button in javafx example. It is also possible to create...

5 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 PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX ID selector

In the JavaFX application, in order to apply various css effect using the id selector, we use the various css classes available in the JavaFX. This is generally used to...

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 Light Distant

In the JavaFX application, in order to apply various Light Distant effect from a single source, we use this class. It has the ability to apply light from a distant...

4 minutes read.

JavaFX Image Input

In the JavaFX application, in order to apply various image input effect, we use the ImageInput class. It has the ability to fill the specified shape with a given image...

4 minutes read.

JavaFX Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the colors in these shapes using the setFill()...

6 minutes read.

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...

4 minutes read.

JavaFX Translation

In the JavaFX application, in order to apply various Translate effect, we use this class. It has the ability to Translate the given object according to the specified parameter. All...

4 minutes read.