Class SwingSizingUtils

java.lang.Object
edu.cnu.mdi.swing.SwingSizingUtils

public final class SwingSizingUtils extends Object
Scale-aware helpers for deriving Swing sizes from rendered content.
  • Method Details

    • preferredWidth

      public static int preferredWidth(int minimumWidth, Component... components)
      Return the greatest preferred width among a baseline and components.
    • preferredSizeAtLeast

      public static Dimension preferredSizeAtLeast(Component component, int minimumWidth, int minimumHeight)
      Return a component's preferred size enlarged to the given baselines.
    • fontHeight

      public static int fontHeight(Component component, Font font, int verticalPadding)
      Return rendered font height plus total vertical padding.
    • textWidth

      public static int textWidth(Component component, String text, int horizontalPadding)
      Return the rendered width of text plus total horizontal padding.
    • textColumnWidth

      public static int textColumnWidth(Component component, int columns, int minimumWidth, int horizontalPadding)
      Return a conservative rendered width for a number of text columns.
    • iconButtonSize

      public static Dimension iconButtonSize(Icon icon, Insets margins, Dimension minimum)
      Return an icon-safe size including margins and a minimum baseline.
    • requiredHorizontalToolbarHeight

      public static int requiredHorizontalToolbarHeight(JToolBar toolbar)
      Return the minimum height that can contain every visible component in a horizontal toolbar, including the toolbar's border insets.
      Parameters:
      toolbar - toolbar to measure, or null
      Returns:
      minimum safe height, at least one pixel
    • availableDesktopWidth

      public static int availableDesktopWidth(JInternalFrame frame)
      Return usable width to the right of an internal frame within its virtual desktop column.

      MDI implements virtual columns by offsetting frame X coordinates by whole desktop widths. Consequently, an off-screen frame can have a very large positive or negative X coordinate. Reducing that coordinate modulo the desktop width recovers its column-local position.