×

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 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 Area Chart

In the JavaFX application, in order to create Area Chart, the AreaChart class is used. The Area Chart allows us to plot data along the XY plane. All methods needed...

3 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 File Chooser

In the JavaFX application, in order to open or save the file, FileChooser is used. It allows user to choose the file from system location and save it in a...

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.

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 Selectors

In the JavaFX application, in order to apply various css effect, we use the various css classes available in the JavaFX. This is generally used to enhance the appearance property...

4 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 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 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 Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

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

In the JavaFX application, in order to show the progress of work ProgressBar is used. It shows how much work is done. In order to use ProgressBar in JavaFX, javafx.scene.control.ProgressBar...

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 Drop Shadow

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

4 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 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 Event Filters

In JavaFX, in order to handle the event which are created by any of the mouse action, keyboard action, rotate action, scroll action Event filters are used. The event filters...

3 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

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