Kensoft PH
  • Download
  • Contact
  • About
Java Quiz
No Result
View All Result
Kensoft PH
  • Download
  • 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
131
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

  • 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

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

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide
Java

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide

March 26, 2023
4
File Chooser in JavaFX Tutorial
Java

File Chooser in JavaFX: 100% Perfect Step-by-Step Guide

March 4, 2023
19
JavaFX TabPane Tutorial
Java

How to use the TabPane in JavaFX | 100% Perfect Tutorial

March 2, 2023
12
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 *

Maximum upload file size: 20 MB. You can upload: image, audio, video, document, text. Drop files here

  • Trending
  • Comments
  • Latest
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
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
JavaFX 17

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

November 15, 2021 - Updated on December 13, 2021
change the stage icon in JavaFX

How to change the stage icon in JavaFX | 100% best for beginners

May 23, 2021 - Updated on September 24, 2022
Failed to automatically set up a JavaFX Platform

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

send SMS in java

How to send SMS in Java | 100% best example

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

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide

March 26, 2023
File Chooser in JavaFX Tutorial

File Chooser in JavaFX: 100% Perfect Step-by-Step Guide

March 4, 2023
JavaFX TabPane Tutorial

How to use the TabPane in JavaFX | 100% Perfect Tutorial

March 2, 2023
How to use the JavaFX ToolBar

How to use the JavaFX ToolBar | 100% Perfect Tutorial

January 24, 2023

Latest Tutorials

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide

March 26, 2023
File Chooser in JavaFX Tutorial

File Chooser in JavaFX: 100% Perfect Step-by-Step Guide

March 4, 2023
JavaFX TabPane Tutorial

How to use the TabPane in JavaFX | 100% Perfect Tutorial

March 2, 2023

Popular Tutorials

  • Failed to automatically set up a JavaFX Platform

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

    0 shares
    Share 0 Tweet 0
  • How to connect Java to MySQL database using Xampp server | 100% best for beginners

    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! Kent is my name. 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.

Website

Privacy Policy

Terms and Condition

Sitemap

Services

Guest Post

Fiverr

Freelancer

Upwork

Categories

Website Status

Check the status

Latest Tutorials

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide

JavaFX DirectoryChooser: 100% Perfect Step-By-Step Guide

March 26, 2023
File Chooser in JavaFX Tutorial

File Chooser in JavaFX: 100% Perfect Step-by-Step Guide

March 4, 2023
JavaFX TabPane Tutorial

How to use the TabPane in JavaFX | 100% Perfect Tutorial

March 2, 2023

© 2023 Made With Love By KENSOFT PH

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

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