Class HTMLScrollPaneSkin

java.lang.Object
javafx.scene.control.SkinBase<javafx.scene.control.ScrollPane>
one.jpro.platform.htmlscrollpane.HTMLScrollPaneSkin
All Implemented Interfaces:
javafx.scene.control.Skin<javafx.scene.control.ScrollPane>

public class HTMLScrollPaneSkin extends javafx.scene.control.SkinBase<javafx.scene.control.ScrollPane>
The HTMLScrollPaneSkin class provides a custom skin for the JavaFX ScrollPane control, enabling the integration of HTML content within the scroll pane. This skin leverages the HTMLView component to render HTML content and manages resource cleanup to prevent memory leaks by monitoring the visibility of the associated ScrollPane using the TreeShowing utility.

In JavaFX applications, embedding HTML content within UI components like ScrollPane can lead to resource retention issues if animations or background tasks continue running after the node is no longer visible. The HTMLScrollPaneSkin addresses this by:

  • Embedding an HTMLView within the scroll pane to display HTML content.
  • Monitoring the ScrollPane's visibility using TreeShowing to manage animations and background tasks effectively.
  • Implementing workarounds for internal JavaFX behaviors to ensure proper resource cleanup.

By using HTMLScrollPaneSkin, developers can seamlessly integrate HTML content into scrollable regions of their JavaFX applications while maintaining optimal memory and resource management.

Example Usage:


 import javafx.application.Application;
 import javafx.scene.Scene;
 import javafx.scene.control.ScrollPane;
 import javafx.stage.Stage;

 public class HTMLScrollPaneExample extends Application {
     @Override
     public void start(Stage primaryStage) {
         ScrollPane scrollPane = new ScrollPane();

         // Apply the custom HTMLScrollPaneSkin
         scrollPane.setSkin(new HTMLScrollPaneSkin(scrollPane, "additional-attributes"));

         Scene scene = new Scene(scrollPane, 800, 600);
         primaryStage.setScene(scene);
         primaryStage.setTitle("HTMLScrollPaneSkin Example");
         primaryStage.show();
     }

     public static void main(String[] args) {
         launch(args);
     }
 }
 

In this example, a ScrollPane is created and assigned the HTMLScrollPaneSkin with additional attributes. The skin manages the embedding of HTML content and ensures that resources are properly cleaned up when the scroll pane is no longer part of the scene graph.

See Also:
  • ScrollPane
  • HTMLView
  • TreeShowing
  • Constructor Summary

    Constructors
    Constructor
    Description
    HTMLScrollPaneSkin(javafx.scene.control.ScrollPane control)
    Creates a new instance with the given ScrollPane control.
    HTMLScrollPaneSkin(javafx.scene.control.ScrollPane control, String attributes)
    Creates a new instance of HTMLScrollPaneSkin with the given ScrollPane control and attributes.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    setupHTMLView(com.jpro.webapi.WebAPI webapi)
    Sets up the HTMLView for the given WebAPI.
    static void
    workaroundClearNewEventTargets(javafx.scene.Scene scene)
    Workaround method to clear the newEventTargets list of the mouseHandler in a Scene using reflection.
    static void
    workaroundOwnerWindow(javafx.stage.Window window)
    Workaround method to set the ownerWindow of a Window to null using reflection.
    static void
    workaroundRemovePeerParent(javafx.scene.Node node)
    Workaround method to remove the parent reference of a Node's peer using reflection.

    Methods inherited from class javafx.scene.control.SkinBase

    computeBaselineOffset, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, consumeMouseEvents, dispose, executeAccessibleAction, getChildren, getClassCssMetaData, getCssMetaData, getNode, getSkinnable, layoutChildren, layoutInArea, layoutInArea, layoutInArea, positionInArea, positionInArea, pseudoClassStateChanged, queryAccessibleAttribute, registerChangeListener, registerInvalidationListener, registerListChangeListener, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, unregisterChangeListeners, unregisterInvalidationListeners, unregisterListChangeListeners

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HTMLScrollPaneSkin

      public HTMLScrollPaneSkin(javafx.scene.control.ScrollPane control)
      Creates a new instance with the given ScrollPane control.
      Parameters:
      control - the ScrollPane control to be associated with the skin
    • HTMLScrollPaneSkin

      public HTMLScrollPaneSkin(javafx.scene.control.ScrollPane control, String attributes)
      Creates a new instance of HTMLScrollPaneSkin with the given ScrollPane control and attributes.
      Parameters:
      control - the ScrollPane control to be associated with the skin
      attributes - a string containing any additional attributes
  • Method Details

    • setupHTMLView

      public void setupHTMLView(com.jpro.webapi.WebAPI webapi)
      Sets up the HTMLView for the given WebAPI.
      Parameters:
      webapi - the WebAPI to be associated with the HTMLView
    • workaroundRemovePeerParent

      public static void workaroundRemovePeerParent(javafx.scene.Node node)
      Workaround method to remove the parent reference of a Node's peer using reflection.
      Parameters:
      node - the Node whose peer's parent reference needs to be removed
    • workaroundClearNewEventTargets

      public static void workaroundClearNewEventTargets(javafx.scene.Scene scene)
      Workaround method to clear the newEventTargets list of the mouseHandler in a Scene using reflection.
      Parameters:
      scene - the Scene whose mouseHandler's newEventTargets list needs to be cleared
    • workaroundOwnerWindow

      public static void workaroundOwnerWindow(javafx.stage.Window window)
      Workaround method to set the ownerWindow of a Window to null using reflection.
      Parameters:
      window - the Window whose ownerWindow needs to be set to null