Kensoft PH
  • Download
    • KenshotApplication
  • Contact
  • About
Java Quiz
No Result
View All Result
Kensoft PH
  • Download
    • KenshotApplication
  • Contact
  • About
Java Quiz
No Result
View All Result
Kensoft PH
No Result
View All Result
Home Java

How to use the JavaFX Hyperlink | 100% Perfect for beginner

May 24, 2022 - Updated on December 10, 2022
in Java
Reading Time: 3 mins read
0
JavaFX Hyperlink
330
VIEWS
Share on FacebookShare on TwitterShare via Email

JavaFX Hyperlink looks like a hyperlink on a web page, but it is not. The hyperlink on a web page is used to navigate to another web page, while the hyperlink in JavaFX is different because you are free to perform anything using the action event.

Contents

Toggle
  • How to use the JavaFX Hyperlink
    • JavaFX Hyperlink Example
    • Create the Hyperlink
    • Adding to layout
    • Open a website using Hyperlink and WebView
      • Output
    • Open a website using Hyperlink and Desktop class
      • Output
  • YouTube Video

How to use the JavaFX Hyperlink

JavaFX Hyperlink is a control that is simply a button styled to look like a hyperlink on a web page. The hyperlink has the same appearance as the hyperlink on a webpage, it can have focus, and it does have a dashed rectangular border when it has focus. When you hover over the hyperlink, the cursor changes to a hand-type cursor and its text will change to underline.

It contains a visited property of BooleanProperty type. When the hyperlink is activated or clicked for the first time, it is considered a “visited,” and the visited property is set to true automatically. The color is different whether the hyperlink is visited or not. The following example will show you a demonstration of how we use the hyperlink control in JavaFX.

JavaFX Hyperlink Example

This tutorial will teach you how to use the JavaFX Hyperlink—for example, creating the hyperlink control in JavaFX and adding the hyperlink to our layout. The primary example in this tutorial is to show you how to open a web page using the JavaFX WebView and Desktop class in JavaFX.

Create the Hyperlink

It is effortless to create a JavaFX Hyperlink. We need to make an object or instantiate the hyperlink constructor. Please proceed to the example below to learn more about creating the hyperlink control in JavaFX.

// Create the hyperlink
Hyperlink hyperlink = new Hyperlink("Hyperlink");

Adding to layout

We need to use the getChildren() method to add a hyperlink to the layout in JavaFX. If you are unfamiliar with the layout in JavaFX, you can learn more at the given link and proceed below to learn more about adding the hyperlink control in JavaFX.

StackPane root = new StackPane();
root.getChildren().add(hyperlink);

Open a website using Hyperlink and WebView

We can do whatever we want in the JavaFX Hyperlink because we are free to perform any action in the ActionEvent handler. This example will teach you how to open a URL from the Hyperlink control and display the webpage on our WebView. Please proceed below to learn more about opening a URL in the JavaFX WebView.

//Lets create an Action Event in our Hyperlink
hyperlink.setOnAction(event ->{
    WebView view = new WebView();
    view.getEngine().load("https://kensoftph.com");
});

Output

JavaFX Hyperlink WebView

Open a website using Hyperlink and Desktop class

The Desktop class is different, and we can open a URL using the Desktop class in the default browser in our application. If you are unfamiliar with the Desktop class, you can learn more about using the class, and the link is given above. The following example below shows how to open a URL in JavaFX using the Desktop class. Please proceed below to learn more about it. Again, we will use the ActionEvent to perform the command.

// Open a URL using the Desktop class in JavaFX
hyperlink.setOnAction(event ->{
    Desktop desktop = Desktop.getDesktop();
    desktop.browse(java.net.URI.create("https://google.com"));
});

Output

Hyperlink in JavaFX

YouTube Video

YouTube video

Previous Post

JavaFX Label Tutorial | 100% Perfect for beginners

Next Post

How to use the JavaFX MenuButton | 100% Perfect Tutorial

KENSOFT

KENSOFT

What’s up! Kent is my name. The name KENSOFT is derived from the words Kent and Software. My programming language of choice is Java

Related tutorials

How to Use the JavaFX Pie Chart 100% For Beginners
Java

How to Use the JavaFX Pie Chart 100% For Beginners

June 12, 2024 - Updated on October 6, 2024
205
How to Connect to an API Using JavaFX
Java

How to Connect to an API Using JavaFX

May 26, 2024 - Updated on September 28, 2024
216
JavaFX SQLite Database CRUD Tutorial
Java

JavaFX SQLite Database CRUD Tutorial | Note Application

May 26, 2024 - Updated on September 28, 2024
590
Next Post
JavaFX MenuButton

How to use the JavaFX MenuButton | 100% Perfect Tutorial

JavaFX Toggle Button

Toggle Button in JavaFX | 100% Perfect for beginners

RadioButton in JavaFX

RadioButton in JavaFX | 100% Perfect for beginners

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tools

Multi-platform installer builder

Java profiler

  • Trending
  • Comments
  • Latest
MySQL database using XAMPP

How to connect Java to MySQL database using Xampp server | 100% best for beginners

October 27, 2020 - Updated on January 23, 2023
Failed to automatically set up a JavaFX Platform

Failed to automatically set up a JavaFX Platform SOLVED Apache NetBeans 12.3 | Best way

April 11, 2021 - Updated on July 3, 2022
JavaFX 17

How To install JDK 17 and JavaFX 17 on NetBeans IDE | Best

November 15, 2021 - Updated on December 13, 2021
hide and show password in jPasswordField

JPasswordField in Java Hide or Show Password | 100% best for beginners

April 2, 2021 - Updated on September 21, 2022
Failed to automatically set up a JavaFX Platform

Failed to automatically set up a JavaFX Platform SOLVED Apache NetBeans 12.3 | Best way

3DES in Java and AES in Java

How to use AES and 3DES in Java | 100% best for beginners

JavaFX Splash Screen

How to create JavaFX Splash Screen | 100% best for beginners

set up JavaFX and Scene Builder

How to set up JavaFX and Scene Builder in NetBeans IDE | 100% best for beginners

How to Use the JavaFX Pie Chart 100% For Beginners

How to Use the JavaFX Pie Chart 100% For Beginners

June 12, 2024 - Updated on October 6, 2024
How to Connect to an API Using JavaFX

How to Connect to an API Using JavaFX

May 26, 2024 - Updated on September 28, 2024
JavaFX SQLite Database CRUD Tutorial

JavaFX SQLite Database CRUD Tutorial | Note Application

May 26, 2024 - Updated on September 28, 2024
How to take a screenshot on PC using Kenshot

How to Take a Screenshot on PC Using Kenshot: A Full Guide

January 18, 2024 - Updated on October 6, 2024

Latest Tutorials

How to Use the JavaFX Pie Chart 100% For Beginners

How to Use the JavaFX Pie Chart 100% For Beginners

June 12, 2024 - Updated on October 6, 2024
How to Connect to an API Using JavaFX

How to Connect to an API Using JavaFX

May 26, 2024 - Updated on September 28, 2024
JavaFX SQLite Database CRUD Tutorial

JavaFX SQLite Database CRUD Tutorial | Note Application

May 26, 2024 - Updated on September 28, 2024

Popular Tutorials

  • MySQL database using XAMPP

    How to connect Java to MySQL database using Xampp server | 100% best for beginners

    0 shares
    Share 0 Tweet 0
  • Failed to automatically set up a JavaFX Platform SOLVED Apache NetBeans 12.3 | Best way

    0 shares
    Share 0 Tweet 0
  • How To install JDK 17 and JavaFX 17 on NetBeans IDE | Best

    0 shares
    Share 0 Tweet 0
Facebook Instagram Youtube Github LinkedIn Discord
Kensoft PH

What’s up! I'm Kent. The name KENSOFT is derived from the words Kent and Software. My programming language of choice is Java, which I use to create computer applications. In a company, I created applications and a website.

Categories

Website

Check the status

Privacy Policy

Terms and Condition

Sitemap

Latest Tutorials

How to Use the JavaFX Pie Chart 100% For Beginners

How to Use the JavaFX Pie Chart 100% For Beginners

June 12, 2024 - Updated on October 6, 2024
How to Connect to an API Using JavaFX

How to Connect to an API Using JavaFX

May 26, 2024 - Updated on September 28, 2024
JavaFX SQLite Database CRUD Tutorial

JavaFX SQLite Database CRUD Tutorial | Note Application

May 26, 2024 - Updated on September 28, 2024

© 2024 Made With Love By KENSOFT PH

No Result
View All Result
  • Download
    • Kenshot
  • Contact
  • About
  • Java Quiz

© 2024 Made With Love By KENSOFT PH

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.