Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.
In this Quick Start Guide you will learn how to download JxBrowser library, get evaluation license, create and run your first JavaFX application that loads and displays HTML content from string.
Requirements: JDK 1.8 and higher.
Note: The instruction about how to perform the following actions in your favorite IDE you can find at IntelliJ IDEA, Eclipse or NetBeans
1. Download Library
To download JxBrowser library navigate to http://www.teamdev.com/jxbrowser and click Download button. Unzip the downloaded archive into some directory (e.g. D:\Projects\MyProject\). When you unzip the archive it will give you directory structure inside D:\Projects\MyProject\ as follows:
lib\ jxbrowser.jar // JxBrowser library jxbrowser-win32.jar // Chromium 32-bit binaries for Windows jxbrowser-win64.jar // Chromium 64-bit binaries for Windows jxbrowser-mac.jar // Chromium 64-bit binaries for Mac OS X jxbrowser-linux64.jar // Chromium 64-bit binaries for Linux 64-bit samples\ // API samples doc\javadoc\ // Public API Javadocs doc\guide\ // Programmer's and Quick Start Guide demo\ // Demo application Readme.txt // Readme file License agreement.txt // License agreement
2. Get License
To get free JxBrowser 30-days evaluation license please fill the web form and click Download Evaluation Key button. You will receive an email with a link that you can use to download evaluation license — license.jar. Download the license.jar file and save it in the D:\Projects\MyProject\lib\ directory.
lib\ jxbrowser.jar // JxBrowser library jxbrowser-win32.jar // Chromium 32-bit binaries for Windows jxbrowser-win64.jar // Chromium 64-bit binaries for Windows jxbrowser-mac.jar // Chromium 64-bit binaries for Mac OS X jxbrowser-linux64.jar // Chromium 64-bit binaries for Linux 64-bit license.jar // Free 30-day evaluation license
3. Create Java Project
Create a new Java Project using your favorite IDE.
4. Add Libraries
In your favorite IDE add JxBrowser libraries and evaluation license in the Project:
D:\Projects\MyProject\lib\jxbrowser.jar D:\Projects\MyProject\lib\jxbrowser-win32.jar D:\Projects\MyProject\lib\jxbrowser-win64.jar D:\Projects\MyProject\lib\jxbrowser-mac.jar D:\Projects\MyProject\lib\jxbrowser-linux64.jar D:\Projects\MyProject\lib\license.jar
5. Create HelloWorld Example
In Java Project create a new HelloWorld java class with the following content.
/* * Copyright (c) 2000-2017 TeamDev Ltd. All rights reserved. * TeamDev PROPRIETARY and CONFIDENTIAL. * Use is subject to license terms. */ import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.BrowserCore; import com.teamdev.jxbrowser.chromium.internal.Environment; import com.teamdev.jxbrowser.chromium.javafx.BrowserView; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.stage.Stage; /** * The sample demonstrates how to create Browser instance, embed it, * load HTML content from string, and display it. */ public class HelloWorld extends Application { @Override public void init() throws Exception { // On Mac OS X Chromium engine must be initialized in non-UI thread. if (Environment.isMac()) { BrowserCore.initialize(); } } @Override public void start(Stage primaryStage) { Browser browser = new Browser(); BrowserView browserView = new BrowserView(browser); StackPane pane = new StackPane(); pane.getChildren().add(browserView); Scene scene = new Scene(pane, 500, 400); primaryStage.setTitle("JxBrowser: JavaFX - Hello World"); primaryStage.setScene(scene); primaryStage.show(); browser.loadHTML("<html><body><h1>Hello World!</h1></body></html>"); } public static void main(String[] args) { launch(args); } }
6. Run the Program
Compile and run HelloWorld program. You will see the following window: