Class BrowserPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public abstract class BrowserPanel extends JPanel
JPanel that includes a web browser and methods to interact with page content. Initial content must be set through BrowserFactory create methods, not from loadUrl/loadHtml. Methods loadUrl/loadHtml have no effect when called before browser initialization finishes. They should be used to update the content after initial content was rendered.

To send messages to the page, use sendMessage or runJsScript.

To receive messages initiated by the page, set the BrowserListener and override onMessage. From the page, call bmMessage(String message, function callback). Argument callback is optional and can be used to receive a response from Java code.

See velox.gui.debug.DebugUi in the main module and browser-submit-demo.html for usage examples.

Threading. Methods defined here can be called from any thread.

See Also:
  • Constructor Details

    • BrowserPanel

      public BrowserPanel()
  • Method Details

    • setListener

      public abstract void setListener(BrowserListener browserListener)
    • loadUrl

      public abstract void loadUrl(String url)
    • loadHtml

      public abstract void loadHtml(String html)
      Parameters:
      html - Content to render.

      Limitation: HTML size here is limited to ~1 MB in CEF.

    • sendMessage

      public abstract void sendMessage(String jsFunction, @Nullable String message, @Nullable Consumer<String> callback)
      Call the given JS function on the loaded page with the given message. Get the return value in the callback.
    • runJsScript

      public abstract void runJsScript(String script, @Nullable Consumer<String> callback)
      Evaluates the given script in the main frame and passes the result to callback.

      To debug script errors, set the debug level to TRACE.