Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8090156

[Mac,JFXPanel] WebEngine: new Tab doesn't load web page

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 8u25, 9
    • Fix Version/s: 9
    • Component/s: javafx
    • Environment:

      OS X 10.10

    • Subcomponent:
      web

      Description

      If I click on link in the web page to open in new window then new tab is created but web page is not loaded in new tab.

      Test program:

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Scene;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.paint.Color;
      import javafx.scene.web.PopupFeatures;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      public class Test {

          private static void initAndShowGUI() {
              JFrame frame = new JFrame("Swing and JavaFX");
              final JFXPanel fxPanel = new JFXPanel();
              frame.add(fxPanel);
              frame.setSize(750, 500);
              frame.setVisible(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              Platform.runLater(() -> {
                  initFX(fxPanel);
              });
          }

          private static void initFX(JFXPanel fxPanel) {
              Scene scene = createScene();
              fxPanel.setScene(scene);
          }

          private static Scene createScene() {
              TabPane root = new TabPane();
              Scene scene = new Scene(root, Color.ALICEBLUE);
              root.getTabs().add(new Browser(root));
              return (scene);
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> {
                  initAndShowGUI();
              });
          }
      }

      class Browser extends Tab {

          final WebView browser = new WebView();
          final WebEngine webEngine = browser.getEngine();
          final TabPane pane;

          public Browser(TabPane tabPane) {
              pane = tabPane;
              webEngine.load("http://www.google.com");
              setContent(browser);
              setText("tab");

              webEngine.setCreatePopupHandler((PopupFeatures config) -> {
                  Browser b = new Browser(pane);
                  pane.getTabs().add(b);
                  return b.webEngine;
              });
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              asrivastava Ankit Srivastava
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: