CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-miglayout--miglayout-swing

MiGLayout Swing implementation providing constraint-based layout management for Java Swing applications

Pending
Overview
Eval results
Files

component-integration.mddocs/

Component Integration

Component wrapper system providing seamless integration between Swing components and the MiGLayout constraint system. These classes bridge the gap between Swing's component model and MiGLayout's internal layout engine.

Capabilities

SwingComponentWrapper

Wrapper for individual Swing components to integrate with the MiGLayout constraint system.

/**
 * Component wrapper for individual Swing components.
 * Implements ComponentWrapper to provide MiGLayout integration.
 */
public class SwingComponentWrapper implements ComponentWrapper {
    
    /**
     * Creates wrapper for Component.
     * @param c The Swing component to wrap.
     */
    public SwingComponentWrapper(Component c);
    
    /**
     * Returns the baseline for the specified width and height.
     * @param width The width to get the baseline for. Use -1 to use current width.
     * @param height The height to get the baseline for. Use -1 to use current height.
     * @return The baseline or -1 if this component does not have a reasonable baseline.
     */
    public final int getBaseline(int width, int height);
    
    /**
     * Returns the wrapped component.
     * @return The wrapped Swing component.
     */
    public final Object getComponent();
    
    /**
     * Returns the pixel unit conversion factor.
     * @param isHor If the factor is for horizontal or vertical.
     * @return The factor to multiply with an inch, point or millimeter to get pixels.
     */
    public final float getPixelUnitFactor(boolean isHor);
}

Component Positioning and Sizing

Methods for getting and setting component bounds and size information.

/**
 * Returns the current x coordinate of the component.
 * @return The x coordinate.
 */
public final int getX();

/**
 * Returns the current y coordinate of the component.
 * @return The y coordinate.
 */
public final int getY();

/**
 * Returns the current height of the component.
 * @return The height.
 */
public final int getHeight();

/**
 * Returns the current width of the component.
 * @return The width.
 */
public final int getWidth();

/**
 * Returns the screen location x coordinate.
 * @return The screen x coordinate.
 */
public final int getScreenLocationX();

/**
 * Returns the screen location y coordinate.
 * @return The screen y coordinate.
 */
public final int getScreenLocationY();

/**
 * Sets the bounds of the component.
 * @param x The x coordinate.
 * @param y The y coordinate.
 * @param width The width.
 * @param height The height.
 */
public final void setBounds(int x, int y, int width, int height);

/**
 * Returns if the component is visible.
 * @return True if visible.
 */
public boolean isVisible();

Size Calculation Methods

Methods for calculating minimum, preferred, and maximum sizes.

/**
 * Returns the minimum height for the specified width.
 * @param sz The size hint or -1 for no hint.
 * @return The minimum height.
 */
public final int getMinimumHeight(int sz);

/**
 * Returns the minimum width for the specified height.
 * @param sz The size hint or -1 for no hint.
 * @return The minimum width.
 */
public final int getMinimumWidth(int sz);

/**
 * Returns the preferred height for the specified width.
 * @param sz The size hint or -1 for no hint.
 * @return The preferred height.
 */
public final int getPreferredHeight(int sz);

/**
 * Returns the preferred width for the specified height.
 * @param sz The size hint or -1 for no hint.
 * @return The preferred width.
 */
public final int getPreferredWidth(int sz);

/**
 * Returns the maximum height for the specified width.
 * @param sz The size hint or -1 for no hint.
 * @return The maximum height or Integer.MAX_VALUE if not set.
 */
public final int getMaximumHeight(int sz);

/**
 * Returns the maximum width for the specified height.
 * @param sz The size hint or -1 for no hint.
 * @return The maximum width or Integer.MAX_VALUE if not set.
 */
public final int getMaximumWidth(int sz);

Component Information Methods

Methods for getting component metadata and properties.

/**
 * Returns the parent container wrapper.
 * @return The parent container wrapper or null if no parent.
 */
public final ContainerWrapper getParent();

/**
 * Returns the horizontal screen DPI.
 * @return The horizontal DPI.
 */
public final int getHorizontalScreenDPI();

/**
 * Returns the vertical screen DPI.
 * @return The vertical DPI.
 */
public final int getVerticalScreenDPI();

/**
 * Returns the screen width.
 * @return The screen width in pixels.
 */
public final int getScreenWidth();

/**
 * Returns the screen height.
 * @return The screen height in pixels.
 */
public final int getScreenHeight();

/**
 * Returns if the component has a baseline.
 * @return True if the component has a baseline.
 */
public final boolean hasBaseline();

/**
 * Returns the component name for linking.
 * @return The component name or null.
 */
public final String getLinkId();

/**
 * Returns the visual padding array.
 * @return Visual padding as [top, left, bottom, right] or null if none.
 */
public final int[] getVisualPadding();

/**
 * Returns the component type constant.
 * @param disregardScrollPane If scroll panes should be disregarded.
 * @return The component type constant.
 */
public int getComponentType(boolean disregardScrollPane);

/**
 * Returns the layout hash code.
 * @return Hash code for layout calculations.
 */
public int getLayoutHashCode();

/**
 * Returns the content bias direction.
 * @return The content bias or -1 if none.
 */
public int getContentBias();

Debug and Visualization

Methods for debug visualization and layout troubleshooting.

/**
 * Paints debug outline around the component.
 * @param showVisualPadding Whether to show visual padding outline.
 */
public final void paintDebugOutline(boolean showVisualPadding);

SwingContainerWrapper

Specialized wrapper for Swing Container components extending SwingComponentWrapper functionality.

/**
 * Container wrapper for Swing containers.
 * Extends SwingComponentWrapper and implements ContainerWrapper.
 */
public final class SwingContainerWrapper extends SwingComponentWrapper implements ContainerWrapper {
    
    /**
     * Creates wrapper for Container.
     * @param c The Swing container to wrap.
     */
    public SwingContainerWrapper(Container c);
    
    /**
     * Returns wrapped child components.
     * @return Array of ComponentWrapper instances for child components.
     */
    public ComponentWrapper[] getComponents();
    
    /**
     * Returns the number of child components.
     * @return The component count.
     */
    public int getComponentCount();
    
    /**
     * Returns the container's layout manager.
     * @return The layout manager object.
     */
    public Object getLayout();
    
    /**
     * Returns the component orientation.
     * @return True if left-to-right orientation.
     */
    public final boolean isLeftToRight();
    
    /**
     * Paints debug cell outline for layout debugging.
     * @param x The x coordinate of the cell.
     * @param y The y coordinate of the cell.
     * @param width The width of the cell.
     * @param height The height of the cell.
     */
    public final void paintDebugCell(int x, int y, int width, int height);
    
    /**
     * Returns the component type constant.
     * @param disregardScrollPane If scroll panes should be disregarded.
     * @return Always returns TYPE_CONTAINER.
     */
    public int getComponentType(boolean disregardScrollPane);
    
    /**
     * Returns the layout hash code.
     * @return Hash code for layout calculations.
     */
    public int getLayoutHashCode();
}

Static Configuration Methods

Static methods for configuring wrapper behavior globally.

/**
 * Returns if visual padding is enabled globally.
 * @return True if visual padding is enabled.
 */
public static boolean isVisualPaddingEnabled();

/**
 * Sets visual padding enabled state globally.
 * @param b True to enable visual padding.
 */
public static void setVisualPaddingEnabled(boolean b);

/**
 * @deprecated Java 1.4 is not supported anymore
 * Returns if maximum size is set on Java 1.4.
 * @return True if maximum size is set.
 */
@Deprecated
public static boolean isMaxSizeSetOn1_4();

/**
 * @deprecated Java 1.4 is not supported anymore  
 * Sets maximum size behavior on Java 1.4.
 * @param b True to set maximum size.
 */
@Deprecated
public static void setMaxSizeSetOn1_4(boolean b);

Component Type Constants

Constants for identifying different component types returned by getComponentType().

// Component type constants
public static final int TYPE_UNSET = -1;
public static final int TYPE_UNKNOWN = 0;
public static final int TYPE_CONTAINER = 1;
public static final int TYPE_LABEL = 2;
public static final int TYPE_TEXT_FIELD = 3;
public static final int TYPE_TEXT_AREA = 4;
public static final int TYPE_BUTTON = 5;
public static final int TYPE_LIST = 6;
public static final int TYPE_TABLE = 7;
public static final int TYPE_SCROLL_PANE = 8;
public static final int TYPE_IMAGE = 9;
public static final int TYPE_PANEL = 10;
public static final int TYPE_COMBO_BOX = 11;
public static final int TYPE_SLIDER = 12;
public static final int TYPE_SPINNER = 13;
public static final int TYPE_PROGRESS_BAR = 14;
public static final int TYPE_TREE = 15;
public static final int TYPE_CHECK_BOX = 16;
public static final int TYPE_SCROLL_BAR = 17;
public static final int TYPE_SEPARATOR = 18;
public static final int TYPE_TABBED_PANE = 19;

Usage Examples:

import net.miginfocom.swing.*;
import javax.swing.*;
import java.awt.*;

// Direct wrapper usage (typically internal to MigLayout)
JButton button = new JButton("Test");
SwingComponentWrapper wrapper = new SwingComponentWrapper(button);

// Get component information
int baseline = wrapper.getBaseline(100, 30);
boolean hasBaseline = wrapper.hasBaseline();
int componentType = wrapper.getComponentType(false);

// Container wrapper usage
JPanel panel = new JPanel();
SwingContainerWrapper containerWrapper = new SwingContainerWrapper(panel);

// Get child components
ComponentWrapper[] children = containerWrapper.getComponents();
int childCount = containerWrapper.getComponentCount();
boolean isLTR = containerWrapper.isLeftToRight();

// Global visual padding configuration
SwingComponentWrapper.setVisualPaddingEnabled(true);
if (SwingComponentWrapper.isVisualPaddingEnabled()) {
    // Visual padding is enabled
    int[] padding = wrapper.getVisualPadding();
}

// Component type identification using constants
int componentType = wrapper.getComponentType(false);
if (componentType == SwingComponentWrapper.TYPE_BUTTON) {
    // Handle button-specific logic
} else if (componentType == SwingComponentWrapper.TYPE_TEXT_FIELD) {
    // Handle text field-specific logic
} else if (componentType == SwingComponentWrapper.TYPE_CONTAINER) {
    // Handle container-specific logic
}

// Debug visualization
wrapper.paintDebugOutline(true);
containerWrapper.paintDebugCell(10, 10, 100, 30);

Install with Tessl CLI

npx tessl i tessl/maven-com-miglayout--miglayout-swing

docs

component-integration.md

constraint-configuration.md

index.md

layout-management.md

tile.json