Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)


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.(在本《快速入门指南》中,您将学习如何下载JxBrowser库,获得评估许可证,创建并运行第一个JavaFX应用程序,该应用程序加载并显示HTML内容。)


Requirements: JDK 1.8 and higher.(要求:JDK 1.8及更高版本。)


Note: The instruction about how to perform the following actions in your favorite IDE you can find at IntelliJ IDEA, Eclipse or NetBeans(注意:有关如何在您喜欢的IDE中执行以下操作的说明,可以在IntelliJ IDEA,Eclipse或NetBeans中找到)


1. Download Library(1.下载资料库)

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:  (要下载JxBrowser库,请导航至http://www.teamdev.com/jxbrowser,然后单击“下载”按钮。将下载的归档文件解压缩到某个目录(例如D:\ Projects \ MyProject \)。解压完成后,它在D:\Projects\MyProject\中的目录结构如下所示:)

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(2.获得许可证)

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. (要获得免费的JxBrowser 30天评估许可证,请填写Web表单,然后单击“下载评估密钥”按钮。您将收到一封包含链接的电子邮件,可用于下载评估许可证-license.jar。下载license.jar文件,并将其保存在D:\ Projects \ MyProject \ lib \目录中。)

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(3.创建Java项目)

Create a new Java Project using your favorite IDE.(使用您喜欢的IDE创建一个新的Java项目。)


4. Add Libraries(4.添加库)

In your favorite IDE add JxBrowser libraries and evaluation license in the Project:  (在您最喜欢的IDE中,在项目中添加JxBrowser库和评估许可证:)

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(5.创建HelloWorld示例)

In Java Project create a new HelloWorld java class with the following content.    (在Java Project中,使用以下内容创建一个新的HelloWorld Java类。)

/*
 * 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(6.运行程序)

Compile and run HelloWorld program. You will see the following window:(编译并运行HelloWorld程序。您将看到以下窗口:)