Open Default Browser in Javafx

Hello I’ve seen many of the javafx programmer really likes the facilities of JAVA as everybody likes too. Javafx has capability to run the Java files by using JavaTaskBase, RunnableFuture (Interface). So today I like to present you guys, how can we open the default browser of system from javafx. Let’s begin.

Requirement:

  • Netbeans 6.5 or >
  • Javafx 1.2 or >

Ok Now let’s start with a new project from Netbeans. Start a new project of Java (I’m telling java not javafx). Then create a Java Project name as you want but at here I’m naming it as ‘Browser Starter’ with Java class name ‘BrowserStarter’. Here you have to add a very tiny Java code which opens the Default Browser of System .

Develop Java Jar file

Now that’s all for the Java. You have to do some stuffs . Here we go. Go to properties of your java project and do something like below picture . It will compress your project in jar form then click OK and press “Ctrl F11” for clean build of your project. Now you will see the jar file being made by Netbeans under <project_directory>/dist . Then copy that jar into specific place where you can use it easily for javafx later.

Create new Javafx project

Now let’s make a new javafx project from Netbeans As shown in figure below. Here we have some tricks which helps to import the jar file we’ve created just before ‘BrowserStarter.jar’ into javafx project.

Creating Library in Netbeans

In this step we are going to create a library so that Netbeans would easily get the java jar file i.e. ‘BrowserStarter.jar’ worked in our javafx project.Let’s see how it works. Go to Project Properties as shown in below.

Now click on Library Category > Add Library. The dialog would appear on window which looks something like this.

Now goto Manage Libraries > New Library again there would come a dialog like below. Here I named the Library Name as ‘BrowserOpener’ and clicked OK.

Ok now it’s time for adding jar files to our Library ‘BrowserOpener’ . Click on Add Jar Folders and specify location where you have kept the Java Project jar file i.e. BrowserStarter.jar

Now you can see our custom Library available in Netbeans Library. Simply click Add Library and it will add the library to your javafx project . Now it’s almost done. You can use this library any time you like in javafx project. Let’s see how javafx works our  library.(Create a main class file  if not exist) I’ve a main file named ‘Main.fx’ in my Javafx project and now i’m going to implement my library to javafx.

It’s time to compile and run our application. Please run the project by pressing ‘Shift+ F6’ and now there must be application window like below. Click on Button and you ‘ll be able to browse the url on System default browser.

Thanks for watching this blog.
Please don’t hesitate to comment. 🙂 Good day

1 thought on “Open Default Browser in Javafx”

  1. Great post. I was checking continuously this blog and I am impressed!

    Very useful info specifically the last part 🙂 I care for such
    info much. I was looking for this certain information for a long time.

    Thank you and good luck.

Leave a Reply