Thanks JavaFX: Embedded Browser for NetBeans

Want the source code for the above? Take the SwingInterop JavaFX sample I referred to a few blog entries ago and copy the browser-related bits from the sample into a TopComponent and then you're done:

public final class BrowserTopComponent extends TopComponent {

    private Pane browser;
    private static JFXPanel browserFxPanel;
    private static final int PANEL_WIDTH_INT = 675;
    private static final int PANEL_HEIGHT_INT = 400;

    public BrowserTopComponent() {
        setName(NbBundle.getMessage(BrowserTopComponent.class, "CTL_BrowserTopComponent"));
        setToolTipText(NbBundle.getMessage(BrowserTopComponent.class, "HINT_BrowserTopComponent"));
        setLayout(new BorderLayout());
        browserFxPanel = new JFXPanel();
        add(browserFxPanel, BorderLayout.CENTER);
        Platform.runLater(new Runnable() {
            public void run() {

    private void createScene() {
        browser = createBrowser();
        browserFxPanel.setScene(new Scene(browser));

    private Pane createBrowser() {
        Double widthDouble = new Integer(PANEL_WIDTH_INT).doubleValue();
        Double heightDouble = new Integer(PANEL_HEIGHT_INT).doubleValue();
        WebView view = new WebView();
        view.setMinSize(widthDouble, heightDouble);
        view.setPrefSize(widthDouble, heightDouble);
        final WebEngine eng = view.getEngine();
        final Label warningLabel = new Label("Do you need to specify web proxy information?");
        ChangeListener handler = new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                if (warningLabel.isVisible()) {
        final TextField locationField = new TextField("");
        Button goButton = new Button("Go");
        EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                eng.load(locationField.getText().startsWith("http://") ? locationField.getText()
                        : "http://" + locationField.getText());
        eng.locationProperty().addListener(new ChangeListener<String>() {
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
        GridPane grid = new GridPane();
        grid.setPadding(new Insets(5));
        GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
        GridPane.setConstraints(goButton, 1, 0);
        GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
        GridPane.setConstraints(warningLabel, 0, 2, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
                new ColumnConstraints(widthDouble - 200, widthDouble - 200, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
                new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true));
        grid.getChildren().addAll(locationField, goButton, warningLabel, view);
        return grid;

However, you also need... JavaFX native libraries. I put them into a new folder named 'bin', within build/cluster/modules. Definitely a smoother solution needed here. Right now, the JavaFX SDK for Windows exists, and I believe a build for Mac OSX as well, from where you can get these native libraries. And jfxrt.jar was the only JAR needed from the JavaFX distro.


Very nice!
How do you get this JavaFX application running on Linux (Ubuntu)? AFAIK there's no version available yet :-(

Posted by Stefan on December 09, 2011 at 09:16 AM PST #

I am very grateful to be able to provide such examples. Also very grateful to make a reply to my question and help me complete my desired results. Seen in the RCP and web applications using javafx, I think I will give users a better user experience.
Through your blog I learn and use the RCP technology, thank you for your contribution, I hope when they encounter problems again for your help.

Posted by zhouzx_gogo on December 09, 2011 at 09:30 PM PST #

The JFXPanel is not getting resized when I double-click the tab. But other swing JComponents are working fine.

Posted by Susanta Tewari on December 27, 2011 at 07:32 AM PST #

So you're saying that JavaFX is not as great as Swing? Feel free to blog about that.

Posted by Geertjan on December 27, 2011 at 08:05 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« November 2015