Class SwingUtils

java.lang.Object
uno.anahata.ai.swing.util.SwingUtils

public final class SwingUtils extends Object
General Swing utility methods.
  • Method Details

    • getScrollState

      public static <T> SwingUtils.ScrollState<T> getScrollState(JScrollPane scrollPane, Function<Component, T> anchorExtractor)
      Captures the precise scroll state of a JScrollPane. It identifies the component closest to the center of the viewport as the user's focus, extracts a stable anchor object from it using the provided function, and records the precise pixel offset.
      Type Parameters:
      T - The type of the anchor object.
      Parameters:
      scrollPane - The JScrollPane to inspect.
      anchorExtractor - A function that takes a Component and returns a stable, non-UI anchor object (e.g., a data model object).
      Returns:
      A SwingUtils.ScrollState object, or null if the state could not be determined.