### Padding Example Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Illustrates the syntax for applying padding to components. ```APIDOC ## Padding Example ### Description Examples of padding syntax within MigLayout constraints. ### Method N/A (Constraint) ### Endpoint N/A (Component Constraint) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```json { "example": "\"padding 10 10\" \"pad 5 5 -5 -5\" \"pad 0 0 1 1\"" } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Gap Constraint Examples Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Provides examples of setting default gaps between cells using 'gap', 'gapx', and 'gapy' with various sizing units. ```java "gap 5px 10px" ``` ```java "gap unrel rel" ``` ```java "gapx 10::50" ``` ```java "gapy 0:rel:null" ``` ```java "gap 10! 10!" ``` -------------------------------- ### Sizing Syntax Examples Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Demonstrates various ways to specify component sizes (minimum, preferred, maximum) in MigLayout. Shorter forms are equivalent to more verbose ones. ```java "10" ``` ```java " null:10:null" ``` ```java ":10:" ``` ```java "n:10:n" ``` ```java "10:20" ``` ```java "10:20:null" ``` ```java "10:20:" ``` ```java "10:20:n" ``` ```java "20!" ``` ```java "20:20:20" ``` -------------------------------- ### Debug Painting Examples Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Shows how to enable debug painting for the container, optionally specifying the repaint interval in milliseconds. ```java "debug" ``` ```java "debug 4000" ``` -------------------------------- ### Fill Constraint Examples Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Demonstrates 'fill', 'fillx', and 'filly' constraints which claim all available space for columns and/or rows, requiring components with 'grow'. ```java "fill" ``` ```java "fillx" ``` ```java "filly" ``` -------------------------------- ### Install JavaFX Runtime Manually with Maven Source: https://github.com/mikaelgrev/miglayout/blob/master/javafx/maven.txt Use this Maven command to install the JavaFX runtime JAR into your local repository. Ensure the file path and version match your JavaFX SDK installation. ```bash mvn install:install-file -Dfile=/path-to/javafx-sdk2.0-beta/rt/lib/jfxrt.jar -DgroupId=com.oracle -DartifactId=javafx-runtime -Dversion=2.0 -Dpackaging=jar -DgeneratePom=true ``` -------------------------------- ### Component Constraint Example Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Example of a component constraint string used in layout methods. ```text "width 100px!, grid 3 2, wrap" ``` -------------------------------- ### Create a Complete Form Layout with MiGLayout Source: https://context7.com/mikaelgrev/miglayout/llms.txt Demonstrates a comprehensive form layout using MiGLayout's features for alignment, spanning, wrapping, and component grouping. This example includes labels, input fields, combo boxes, text areas, and buttons. ```java import net.miginfocom.swing.MigLayout; import javax.swing.*; public class CompleteFormExample { public static void main(String[] args) { JPanel panel = new JPanel(new MigLayout( "fillx, wrap 2, insets dialog", // Fill width, wrap after 2, dialog insets "[right]rel[grow,fill]", // Right-aligned labels, growing inputs "[]rel[]rel[]rel[]para[]rel[]" // Regular gaps, paragraph before notes )); // Header spanning both columns JLabel header = new JLabel("Contact Information"); header.setFont(header.getFont().deriveFont(16f)); panel.add(header, "span, align center, gapbottom 10"); panel.add(new JSeparator(), "span, growx, gapbottom 10"); // Standard form fields panel.add(new JLabel("First Name:*")); panel.add(new JTextField(20)); panel.add(new JLabel("Last Name:*")); panel.add(new JTextField(20)); panel.add(new JLabel("Email:*")); panel.add(new JTextField(20)); // Phone with country code in split cell panel.add(new JLabel("Phone:")); JPanel phonePanel = new JPanel(new MigLayout("insets 0, fill")); phonePanel.add(new JComboBox<>(new String[]{σουν", "+44", "+49", "+81"}), "w 60!"); phonePanel.add(new JTextField(), "growx"); panel.add(phonePanel, "growx"); // Multi-line notes field panel.add(new JLabel("Notes:"), "aligny top"); panel.add(new JScrollPane(new JTextArea(4, 20)), "grow, h 80:100:150"); // Required field note panel.add(new JLabel("* Required fields"), "span, align left, gaptop 5"); // Button bar with proper platform ordering panel.add(new JButton("Submit"), "span, split 3, align right, tag ok, sizegroup btn"); panel.add(new JButton("Reset"), "tag other, sizegroup btn"); panel.add(new JButton("Cancel"), "tag cancel, sizegroup btn"); JFrame frame = new JFrame("Contact Form"); frame.setContentPane(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } ``` -------------------------------- ### Wrap Constraint Examples Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Demonstrates the 'wrap' constraint for enabling auto-wrapping of components into new rows or columns after a specified count. ```java "wrap" ``` ```java "wrap 4" ``` -------------------------------- ### Absolute Positioning with x, x2, y, y2 Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Position the start (x or y) or end (x2 or y2) edges of a component in absolute coordinates. This is useful for aligning components within grids or docks. These keywords are applied in the last stage and do not affect other components unless explicitly linked. ```java "x button1.x" ``` ```java "x2 (visual.x2-50)" ``` ```java "x 100, y 300" ``` -------------------------------- ### Initialize MigLayout in Swing Source: https://context7.com/mikaelgrev/miglayout/llms.txt Demonstrates creating a JPanel with string-based layout, column, and row constraints using the MigLayout manager. ```java import net.miginfocom.swing.MigLayout; import javax.swing.*; public class BasicSwingExample { public static void main(String[] args) { JFrame frame = new JFrame("MigLayout Demo"); // String-based constraints JPanel panel = new JPanel(new MigLayout( "fill, wrap 2", // Layout constraints: fill container, wrap after 2 columns "[grow][100px]", // Column constraints: first grows, second is 100px "[][][grow]" // Row constraints: two normal rows, third grows )); panel.add(new JLabel("Name:")); panel.add(new JTextField(20)); panel.add(new JLabel("Email:")); panel.add(new JTextField(20)); panel.add(new JTextArea(), "span 2, grow"); // Spans 2 columns and grows frame.setContentPane(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } ``` -------------------------------- ### Initial Grid Layout with API Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Shows the equivalent layout using MigLayout's API constraint building. This approach offers a programmatic way to define layout constraints, mirroring the functionality of string-based constraints. ```java // Layout, Column and Row constraints as arguments. MigLayout layout = new MigLayout( new LC().fillX(), new AC().align("right").gap("rel").grow().fill(), new AC().gap("10"); JPanel panel = new JPanel(layout); panel.add(new JLabel("Enter size:")); panel.add(new JTextField(""), new CC().wrap()); panel.add(new JLabel("Enter weight:")); panel.add(new JTextField("")); ``` -------------------------------- ### Absolute Positioning and Component Linking with MiGLayout Source: https://context7.com/mikaelgrev/miglayout/llms.txt Illustrates absolute positioning of components using pixel coordinates, relative positioning to other components by ID, and positioning based on container bounds or visual center. Also shows how to link component sizes. ```java import net.miginfocom.swing.MigLayout; import javax.swing.*; public class AbsolutePositioningExample { public static void main(String[] args) { JPanel panel = new JPanel(new MigLayout("")); // Assign IDs to components for linking JButton mainButton = new JButton("Main Button"); panel.add(mainButton, "id main, pos 50 50"); // Position relative to another component panel.add(new JButton("Below Main"), "pos main.x (main.y2+10)"); // Position using expressions panel.add(new JButton("Right of Main"), "pos (main.x2+10) main.y"); // Position relative to container bounds panel.add(new JLabel("Bottom-Right Corner"), "pos (container.x2-100) (container.y2-30)"); // Position using visual bounds (respects insets) panel.add(new JLabel("Visual Center"), "pos 0.5al 0.5al"); // Link component sizes JButton refButton = new JButton("Reference"); panel.add(refButton, "id ref, pos 200 150"); panel.add(new JButton("Same Width"), "pos ref.x (ref.y2+5), w ref.w!"); JFrame frame = new JFrame("Absolute Positioning"); frame.setContentPane(panel); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } ``` -------------------------------- ### Basic MigLayout Panel Creation Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/examples/Example01.html Use this to create a simple panel with MigLayout. Components are added sequentially, wrapping to the next row when 'wrap' is specified. Constraints like 'gap unrelated' and 'span, growx' control spacing and resizing. ```java JPanel panel = new JPanel(new MigLayout()); panel.add(new JLabel("First Name")); panel.add(new JTextField(15)); panel.add(new JLabel("Surname"), "gap unrelated"); // Unrelated size is resolved per platform. panel.add(new JTextField(15), "wrap"); // Wraps to the next row in the grid. panel.add(new JLabel("Address")); panel.add(new JTextField(), "span, growx"); // Spans the rest of the cells in the row // and grows to fit that space. ``` -------------------------------- ### Row/Column Constraint Keywords Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Illustrates using keywords like 'min', 'pref', and 'max' for row/column constraints, and 'null' as a placeholder. ```java "pref:pref" ``` ```java "min:min:pref" ``` -------------------------------- ### Initial Grid Layout with String Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Demonstrates creating a two-row layout with right-aligned labels and growing text fields using string-based MigLayout constraints. Uses default gaps and specifies an inter-row gap of 10 pixels. ```java // Layout, Column and Row constraints as arguments. MigLayout layout = new MigLayout("fillx", "[right]rel[grow,fill]", "[]10[]"); JPanel panel = new JPanel(layout); panel.add(new JLabel("Enter size:"), ""); panel.add(new JTextField(""), "wrap"); panel.add(new JLabel("Enter weight:"), ""); panel.add(new JTextField(""), ""); ``` -------------------------------- ### Configure Component Size Constraints in MiGLayout Source: https://context7.com/mikaelgrev/miglayout/llms.txt Use 'min:preferred:max' syntax or specific keywords like 'w' for width and 'h' for height to define component dimensions. 'growx' and 'growy' enable horizontal and vertical growth, respectively, with optional weights. ```java import net.miginfocom.swing.MigLayout; import javax.swing.*; public class SizeConstraintsExample { public static void main(String[] args) { JPanel panel = new JPanel(new MigLayout("fill, wrap 2", "[right][grow]")); // Size syntax: "min:preferred:max" or "size!" for all three panel.add(new JLabel("Fixed width:")); panel.add(new JTextField(), "w 200!"); // Exactly 200px panel.add(new JLabel("Min 100, pref 200:")); panel.add(new JTextField(), "w 100:200"); // Min 100, pref 200, no max panel.add(new JLabel("Bounded size:")); panel.add(new JTextField(), "w 100:200:300"); // Min 100, pref 200, max 300 panel.add(new JLabel("Grow with weight:")); panel.add(new JTextField(), "growx 200"); // Grow weight 200 panel.add(new JLabel("No shrink:")); panel.add(new JTextField(), "growx, shrinkx 0"); // Won't shrink // Height constraints panel.add(new JLabel("Tall area:"), "ay top"); panel.add(new JScrollPane(new JTextArea()), "grow, h 100:150:300"); // Bounded height // Using expressions panel.add(new JLabel("Computed:")); panel.add(new JTextField(), "w pref+50, h pref*1.5"); // Relative to preferred // Growth priority - higher priority components grow first panel.add(new JLabel("Priority:")); JPanel subPanel = new JPanel(new MigLayout("fill")); subPanel.add(new JButton("Normal"), "growx, growprio 100"); subPanel.add(new JButton("First"), "growx, growprio 200"); // Grows first panel.add(subPanel, "grow"); JFrame frame = new JFrame("Size Constraints"); frame.setContentPane(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } ``` -------------------------------- ### Dock Components to Container Edges with MiGLayout Source: https://context7.com/mikaelgrev/miglayout/llms.txt Demonstrates docking components like toolbars, status bars, and navigation panels to the north, south, and west edges of a container. Docked components are placed outside the main grid and can be stacked on the same edge. ```java import net.miginfocom.swing.MigLayout; import javax.swing.*; import java.awt.*; public class DockingExample { public static void main(String[] args) { JPanel panel = new JPanel(new MigLayout("fill")); // Docked components are placed outside the main grid panel.add(createToolBar(), "dock north"); // Toolbar at top panel.add(createStatusBar(), "dock south"); // Status bar at bottom panel.add(createNavPanel(), "dock west, w 150!"); // Navigation panel // Main content area fills remaining space JTextArea mainContent = new JTextArea("Main content area\nOccupies center space"); panel.add(new JScrollPane(mainContent), "grow"); // Multiple docked components on same side (in order added) panel.add(new JLabel("Info Bar"), "dock south, gaptop 5"); JFrame frame = new JFrame("Docking Layout"); frame.setContentPane(panel); frame.setSize(600, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } static JToolBar createToolBar() { JToolBar bar = new JToolBar(); bar.add(new JButton("New")); bar.add(new JButton("Open")); bar.add(new JButton("Save")); return bar; } static JPanel createStatusBar() { JPanel bar = new JPanel(new MigLayout("insets 2", "[grow][] ")); bar.add(new JLabel("Ready")); bar.add(new JLabel("Line: 1, Col: 1")); return bar; } static JPanel createNavPanel() { JPanel nav = new JPanel(new MigLayout("wrap 1, fill")); nav.add(new JButton("Home"), "growx"); nav.add(new JButton("Documents"), "growx"); nav.add(new JButton("Settings"), "growx"); return nav; } } ``` -------------------------------- ### Visual Debugging Guidelines Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Enabling visual debugging in MigLayout helps in understanding component placement by outlining cells and component bounds. ```APIDOC ## Visual Debugging Guidelines ### Description To enable visual debugging for a MigLayout container, add the `"debug"` constraint to its Layout Constraints. This will trigger an overdraw that outlines the grid cells and component bounds, aiding in layout analysis. ### Method Add constraint to Layout Constraints ### Endpoint N/A (Configuration within layout setup) ### Parameters #### Request Body - **debug** (string) - Required - The string "debug" to be added to the layout constraints. ``` -------------------------------- ### Configure Component Gaps Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Sets spacing around components using BoundSize. Missing values default to 0px. ```text "gap 5px 10px 5px 7px" or "gap unrel rel" or "gapx 5dlu" or "gapx 10:20:50:push" or "gapy 0:rel:null" or "gap 10! 10!" or "gapafter push" ``` -------------------------------- ### Configure Component Splitting Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Use split to place multiple components in the same cell. Only the first component in a cell can define the split. ```text "split" or "split 4" ``` -------------------------------- ### Greedy Gap Syntax Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Shows how to make gaps 'greedy' using the 'push' keyword, allowing them to expand and take available space. ```java "gap rel:push" ``` ```java "[][]\ ``` ```java "10cm!:push" ``` ```java "10:10:10:push" ``` -------------------------------- ### Configure Growth Priority Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Set the priority for growth, ensuring higher priority components reach their maximum size first. ```text "growprio 50 50" or "gp 110 90" or "gpx 200" or "prowprioy 200" ``` -------------------------------- ### Initialize MigPane in JavaFX Source: https://context7.com/mikaelgrev/miglayout/llms.txt Shows the usage of MigPane for JavaFX applications, utilizing string-based constraints for layout, columns, and rows. ```java import org.tbee.javafx.scene.layout.MigPane; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.stage.Stage; public class BasicJavaFXExample extends Application { @Override public void start(Stage stage) { // String-based constraints MigPane pane = new MigPane( "fill, wrap 2, insets 10", // Layout constraints "[right][grow, fill]", // Column constraints "[]10[]10[grow]" // Row constraints with gaps ); pane.add(new Label("Username:")); pane.add(new TextField()); pane.add(new Label("Password:")); pane.add(new PasswordField()); pane.add(new TextArea(), "span 2, grow, height 100:200:300"); stage.setScene(new Scene(pane, 400, 300)); stage.show(); } } ``` -------------------------------- ### Customize MiGLayout Platform Defaults in Java Source: https://context7.com/mikaelgrev/miglayout/llms.txt Use PlatformDefaults to set custom button orders, gaps, and panel insets. Enables global debug mode for visual layout debugging. Requires Swing and MiGLayout libraries. ```java import net.miginfocom.layout.*; import net.miginfocom.swing.MigLayout; import javax.swing.*; public class PlatformDefaultsExample { public static void main(String[] args) { // Get current platform (auto-detected) int platform = PlatformDefaults.getCurrentPlatform(); System.out.println("Platform: " + (platform == PlatformDefaults.WINDOWS ? "Windows" : platform == PlatformDefaults.MAC_OSX ? "macOS" : "Other")); // Customize button order (Windows default: "&L&E&Y+&U+&H>B_C*X") // L=left, E=help2, Y=yes, U=undo, H=help, B=back, C=cancel, X=next // O=ok, N=no, A=apply, F=finish, R=right PlatformDefaults.setButtonOrder("L_H+E+Y+U+B_R+C+O+A+N+F_X"); // Customize default gaps PlatformDefaults.setRelatedGap( UnitValue.parseUnitValue("5px", true), // Horizontal UnitValue.parseUnitValue("5px", false) // Vertical ); PlatformDefaults.setUnrelatedGap( UnitValue.parseUnitValue("10px", true), UnitValue.parseUnitValue("10px", false) ); // Customize panel insets PlatformDefaults.setPanelInsets( UnitValue.parseUnitValue("10px", false), // Top UnitValue.parseUnitValue("10px", true), // Left UnitValue.parseUnitValue("10px", false), // Bottom UnitValue.parseUnitValue("10px", true) // Right ); // Enable global debug mode for all layouts LayoutUtil.setGlobalDebugMillis(500); // Create panel with customized defaults JPanel panel = new JPanel(new MigLayout("wrap 2")); panel.add(new JLabel("Label:")); panel.add(new JTextField(15)); // Buttons will respect the custom order panel.add(new JButton("OK"), "span, split 3, tag ok"); panel.add(new JButton("Cancel"), "tag cancel"); panel.add(new JButton("Help"), "tag help"); JFrame frame = new JFrame("Platform Defaults"); frame.setContentPane(panel); frame.pack(); frame.setVisible(true); } } ``` -------------------------------- ### Configure Component Growth Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Define how components should grow relative to others in the same cell when extra space is available. ```text "grow 50 20" or "growx 50" or "grow" or "growx" or "growy 0" ``` -------------------------------- ### Wrap Component Before Placement Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Wraps to a new column/row before the component is placed. Use 'newline' for default behavior or specify a gap size. ```java "newline" "newline 15px" "newline push" "newline 15:push" ``` -------------------------------- ### Override Min/Max Component Size Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Set specific minimum or maximum size constraints for components. ```text "wmin 10" or "hmax pref+100" ``` -------------------------------- ### Column and Row Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Configuration for individual rows and columns, including sizing, gaps, and size grouping. ```APIDOC ## Column and Row Constraints ### Description Defines the structure and sizing behavior for rows and columns in the grid. ### Format `[constraint1, constraint2, ...]gap size[constraint1, constraint2, ...]gap size[...]` ### Parameters - **sg/sizegroup** (String) - Optional - Assigns a row to a size group; all rows in the group share the largest min/preferred size. - **fill** (Keyword) - Optional - Sets the default component constraint to 'grow' for that dimension. - **nogrid** (Keyword) - Optional - Disables grid behavior for the row/column. ``` -------------------------------- ### Shrink and Shrink Priority Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Defines how components shrink when space is limited and their priority in the shrinking process. ```APIDOC ## shrink [weightx] [weighty] ### Description Sets the relative weight of a component for shrinking. Higher weights shrink more when space is scarce. ### Parameters - **weightx** (number) - Optional - Horizontal shrink weight. - **weighty** (number) - Optional - Vertical shrink weight. ## shrinkprio [priox] [prioy] ### Description Sets the shrink priority. Components with higher priority shrink to their minimum size before those with lower priority. ### Parameters - **priox** (number) - Required - Horizontal shrink priority. - **prioy** (number) - Optional - Vertical shrink priority. ``` -------------------------------- ### Set Component Shrink Priority Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Determines the order in which components shrink. Higher priority components shrink to their minimum size first. ```text "shrinkpriority 50 50 " or "shp 200 200 " or "shpx 110" ``` -------------------------------- ### Wrap Component After Placement Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Wraps to a new column/row after the component is placed. Use 'wrap' for default behavior or specify a gap size. ```java "wrap" "wrap 15px" "wrap push" "wrap 15:push" ``` -------------------------------- ### Override Component Size Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Use width and height constraints to override default component sizes using BoundSize expressions. ```text "width 10!" or "width 10" or "h 10:20" or "height pref!" or "w min:100:pref" or "w 100!,h 100!" or "width visual.x2-pref" ``` -------------------------------- ### Define Component Size Groups Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Groups components to share the same BoundSize, ensuring they match the largest component in the group. ```text "sg" or "sg group1" or "sizegroup props" or "sgx" or "sizegroupy grp1" ``` -------------------------------- ### Define Layout Constraints with LC API Source: https://context7.com/mikaelgrev/miglayout/llms.txt Utilizes the fluent LC API to programmatically define container-level layout constraints for a MigLayout instance. ```java import net.miginfocom.layout.*; import net.miginfocom.swing.MigLayout; import javax.swing.*; public class LCApiExample { public static void main(String[] args) { // Using LC API for layout constraints LC layoutConstraints = new LC() .fill() // Fill both horizontally and vertically .wrap() // Auto-wrap after column constraints count .insets("10 15 10 15") // Top, left, bottom, right insets .gridGap("5px", "5px") // Gap between grid cells .debug(1000); // Enable debug painting every 1000ms // Alternative: chained methods LC lc = new LC().fillX().flowY().wrapAfter(3).hideMode(2); JPanel panel = new JPanel(new MigLayout(layoutConstraints)); // Components will fill available space and wrap automatically for (int i = 1; i <= 9; i++) { panel.add(new JButton("Button " + i), "grow"); } JFrame frame = new JFrame(); frame.setContentPane(panel); frame.setSize(400, 300); frame.setVisible(true); } } ``` -------------------------------- ### Setting Layout Direction (Top-to-Bottom/Bottom-to-Top) Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Determines the direction in which components are added to the grid. Defaults to top-to-bottom. ```java "ttb" ``` ```java "toptobottom" ``` ```java "btt" ``` -------------------------------- ### Layout Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Global constraints for the layout manager, including alignment, orientation, and caching behavior. ```APIDOC ## Layout Constraints ### Description Global settings that affect the entire container layout. ### Parameters - **align** (UnitValue/AlignKeyword) - Optional - Specifies alignment for components as a group. - **ltr/rtl** (Keyword) - Optional - Overrides ComponentOrientation (left-to-right or right-to-left). - **ttb/btt** (Keyword) - Optional - Specifies grid addition direction (top-to-bottom or bottom-to-top). - **hidemode** (Integer) - Optional - Defines how invisible components are handled (0-3). - **nocache** (Keyword) - Optional - Disables the layout engine cache. ``` -------------------------------- ### Component Tagging Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Assigns metadata tags to components, often used for platform-specific button ordering. ```text "tag ok" "tag help2" ``` -------------------------------- ### Defining Column/Row Constraints with Gaps in MigLayout Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Specifies constraints for columns or rows, including their size and the gaps between them. Supports min/preferred/max sizes and 'push' for greedy gaps. ```java "[fill]10[top,10:20]" ``` ```java "[fill]push[]" ``` ```java "[fill]10:10:100:push[top,10:20]" ``` ```java "[100|200|300]" ``` ```java "[10]" ``` -------------------------------- ### Define Column and Row Constraints with AC API Source: https://context7.com/mikaelgrev/miglayout/llms.txt Use the AC class to fluently define column and row sizing, gaps, and alignment for a MigLayout container. ```java import net.miginfocom.layout.*; import net.miginfocom.swing.MigLayout; import javax.swing.*; public class ACApiExample { public static void main(String[] args) { // Column constraints using AC API AC columnConstraints = new AC() .size("80px").gap("10px") // First column: 80px with 10px gap after .size("pref:grow").gap() // Second column: grows, default gap .size("100px"); // Third column: fixed 100px // Row constraints with alignment and growth AC rowConstraints = new AC() .align("top").gap("5px") // First row: top-aligned .fill().gap("10px") // Second row: fill mode for components .grow(); // Third row: can grow // Alternative: index-based specification AC cols = new AC() .index(0).size("label") // First column sized for labels .index(1).grow().fill(); // Second column grows and fills LC lc = new LC().fill().wrap(); JPanel panel = new JPanel(new MigLayout(lc, columnConstraints, rowConstraints)); panel.add(new JLabel("Label 1")); panel.add(new JTextField()); panel.add(new JButton("Browse")); JFrame frame = new JFrame(); frame.setContentPane(panel); frame.pack(); frame.setVisible(true); } } ``` -------------------------------- ### Grow Row/Column with Weight Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Makes the row and/or column that the component resides in grow with 'weight'. Can be used instead of 'grow' in column/row constraints. ```java "push" "pushx 200" "pushy" ``` -------------------------------- ### UnitValue Types Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Detailed explanation of the various unit types supported by MigLayout for defining sizes and positions. ```APIDOC ## UnitValue Types ### Description UnitValue represents a size with a value and a unit type. MigLayout supports a rich set of units for flexible layout definitions. ### Method N/A (Definition of types) ### Endpoint N/A ### Parameters #### Unit Types - **"" (empty string)** - No unit specified. Defaults to pixels. Can be configured using `PlatformDefaults.setDefaultUnit(int)`. - **px** - Pixels. Direct mapping to screen pixels. E.g., `"10px"` or `"10"`. - **%** - Percentage of the container's size. Can also be used for alignment (e.g., `50%` for centered). - **lp** - Logical Pixels. Adapts to platform font size changes. - **pt** - Points (1/72 inch). Used for printing, considers screen DPI. - **mm** - Millimeters. Considers screen DPI. - **cm** - Centimeters. Considers screen DPI. - **in** - Inches. Considers screen DPI. - **sp** - Percentage of the screen. Considers screen pixel size. - **al** - Visual bounds alignment. Used with absolute positioning (e.g., `0al` for left, `0.5al` for center). - **n/null** - Null value. Represents the absence of a value. E.g., `"n"` or `"null"`. ### Related Unit Values - **r/rel/related** - Components or columns/rows are considered related. Size determined by platform defaults. - **u/unrel/unrelated** - Components or columns/rows are considered unrelated. Size determined by platform defaults. - **p/para/paragraph** - Spacing appropriate for a paragraph. Size determined by platform defaults. - **i/ind/indent** - Spacing appropriate for an indent. Size determined by platform defaults. ### Reference Unit Values - **min/minimum** - Reference to the largest minimum size of a column/row. - **p/pref/preferred** - Reference to the largest preferred size of a column/row. - **max/maximum** - Reference to the smallest maximum size of a column/row. ### Component Width Specific Unit Values - **button** - Reference to the platform minimum size for a button. Used only for component width constraints (e.g., `"wmin button"`). ### BoundSize A BoundSize optionally has minimum, preferred, and maximum bounds. Format: `"_min_:_preferred_:_max_"`. A single value sets the preferred size (e.g., `"10"` is equivalent to `":10:"`). ``` -------------------------------- ### Set Component Shrink Weight Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Defines the relative weight for shrinking when space is limited. Defaults to 100 if not specified. ```text "shrink 50" or "shrink 50 40" ``` -------------------------------- ### Component Constraint: tag Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Tags a component with metadata to assist the layout engine, particularly for platform-specific button ordering. ```APIDOC ## tag [name] ### Description Tags the component with a metadata name used by the layout engine to identify the component type (e.g., OK or Cancel buttons). ### Parameters - **name** (string) - Required - The tag identifier. Supported tags: ok, cancel, help, help2, yes, no, apply, next, back, finish, left, right, other. ### Example "tag ok" ``` -------------------------------- ### String-Based Constraints in MiGLayout Source: https://context7.com/mikaelgrev/miglayout/llms.txt Use string-based constraints for layout, column, and row definitions. Common keywords include 'fill', 'wrap', 'debug', 'gap', and 'insets'. Component constraints can specify alignment, size, and spanning. ```java import net.miginfocom.swing.MigLayout; import javax.swing.*; public class StringConstraintsExample { public static void main(String[] args) { // Layout constraints: "keyword value, keyword value, ..." // Common: fill, fillx, filly, wrap [n], debug, nogrid, flowy, insets, gap JPanel panel = new JPanel(new MigLayout( "fill, wrap 2, debug 500", // Layout: fill, wrap after 2, debug every 500ms "[right]10[grow,fill]", // Columns: right-align, 10px gap, grow & fill "[]5[]5[grow]" // Rows: 5px gaps, last row grows )); // Component constraints examples panel.add(new JLabel("User:")); panel.add(new JTextField(), "growx"); // Grow horizontally panel.add(new JLabel("Pass:")); panel.add(new JPasswordField(), "w 200!"); // Fixed width 200px panel.add(new JLabel("Bio:")); panel.add(new JScrollPane(new JTextArea()), "span 1 2, grow, h 100:150:200"); // Span rows, grow, bounded height panel.add(new JLabel("Role:")); // This goes next to Bio panel.add(new JButton("OK"), "span 2, split 2, tag ok, sg btns"); panel.add(new JButton("Cancel"), "tag cancel, sg btns"); JFrame frame = new JFrame("String Constraints"); frame.setContentPane(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } ``` -------------------------------- ### Configure Eclipse VM Arguments for JavaFX Tests Source: https://github.com/mikaelgrev/miglayout/blob/master/javafx/maven.txt When IDEs prevent additional classpath entries, modify the run configuration of each test class to include this VM argument. This points to the JavaFX binaries directory. ```java -Djava.library.path=C:\Progra~1\Oracle\JAVAFX~1.0\bin ``` -------------------------------- ### Configure Row Grow Weight Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Determines how a row grows relative to others. Defaults to 100 if not specified. ```text "grow 50" "grow" ``` -------------------------------- ### Component Sizing and Flow Direction Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Constraints for overriding component dimensions and defining in-cell flow direction. ```APIDOC ## flowx / flowy ### Description Sets the flow direction within the specific cell. ## w / width / h / height ### Description Overrides the default size of the component using BoundSize expressions. ### Parameters - **size** (string) - Required - A BoundSize expression (e.g., 'pref+10px', 'min:100:pref'). ## wmin / wmax / hmin / hmax ### Description Sets the minimum or maximum size constraints for the component. ``` -------------------------------- ### Column and Row Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Defines sizing and gap constraints for rows and columns. ```text "[fill]10[top,10:20]" ``` ```text "[fill]push[]" ``` ```text "[fill]10:10:100:push[top,10:20]" ``` -------------------------------- ### Setting Container Insets in MigLayout Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Defines the padding around the container. Can be set using keywords like 'dialog' or 'panel', or with explicit pixel values for each side. ```java "insets dialog" ``` ```java "ins 0" ``` ```java "insets 10px n n n" ``` ```java "insets 10 20 30 40" ``` -------------------------------- ### Docking Components Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Docks components to the edges of the container, similar to BorderLayout. ```text "dock north" "north" "west, gap 5" ``` -------------------------------- ### Docking Components Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Dock components to the north, west, south, east, or center of the container. This works similarly to BorderLayout but allows multiple docking components. Docking constraints can be combined with other constraints like padding and width/height. ```java "dock north" ``` ```java "north" ``` ```java "west, gap 5" ``` -------------------------------- ### Apply Metadata Tag Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Tags a component with metadata for the layout engine, commonly used for platform-specific button ordering. ```text "tag ok" or "tag help2" ``` -------------------------------- ### Component Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Constraints applied to individual components to control their size and placement within the grid. ```APIDOC ## Component Constraints Component constraints are used as an argument in the `Container.add(...)` for Swing and by setting it as `Control.setLayoutData(...)` in SWT. It can be used to specify constraints that has to do with the component's size and/or the grid cell flow. The format is same as for Layout Constraint, which means that the constraints are specified one by one with comma signs as separators. Example: `"width 100px!, grid 3 2, wrap"`. ### wrap [_gapsize_] Wraps to a new column/row **after** the component has been put in the next available cell. This means that the **next** component will be put on the new row/column. Tip! Read wrap as "wrap after". If specified `"gapsize"` will override the size of the gap between the current and next row (or column if `"flowy"`). Note that the gaps size is **after** the row that this component will end up at. Example: `"wrap" or "wrap 15px" or "wrap push" or "wrap 15:push"` ### newline [_gapsize_] Wraps to a new column/row **before** the component is put in the next available cell. This means that the **this** component will be put on a new row/column. Tip! Read wrap as "on a newline". If specified `"gapsize"` will override the size of the gap between the current and next row (or column if `"flowy"`). Note that the gaps size is **before** the row that this component will end up at. Example: `"newline"` `or "newline 15px" or "newline push" or "newline 15:push"` ### push [_weightx_] [_weighty_] or **pushx**[_weightx_] or **pushy**[_weighty_] Makes the row and/or column that the component is residing in grow with `"weight"`. This can be used instead of having a "grow" keyword in the column/row constraints. Example: `"push" or "pushx 200"`. ### skip [_count_] Skips a number of cells in the flow. This is used to jump over a number of cells before the next free cell is looked for. The skipping is done before this component is put in a cell and thus this cells is affected by it. `"count"` defaults to 1 if not specified. Example: `"skip" or "skip 3"`. ``` -------------------------------- ### Grid and Cell Management Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Constraints for merging cells, splitting cells, and explicit coordinate placement. ```APIDOC ## span / spanx / spany ### Description Spans the current cell over a number of cells, treating them as one. ### Parameters - **count** (integer) - Optional - Number of cells to span. Defaults to end of row/column. ## split ### Description Splits the cell into multiple sub-cells to place multiple components side-by-side. ### Parameters - **count** (integer) - Optional - Number of components to put in the cell. Defaults to infinite. ## cell ### Description Sets the specific grid cell coordinates for the component. ### Parameters - **col** (integer) - Required - Column index. - **row** (integer) - Required - Row index. - **span x** (integer) - Optional - Number of columns to span. - **span y** (integer) - Optional - Number of rows to span. ``` -------------------------------- ### Set Row Grow Priority Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Sets the priority for row growth. Higher priority rows grow to maximum size first. ```text "growprio 50" ``` -------------------------------- ### Assign Component to Size Group Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Assigns a component to a size group, ensuring all components in the group share the same minimum, preferred, and maximum sizes. ```java "sg" "sg group1" "sizegroup props" "sgx" "sizegroupy grp1" ``` -------------------------------- ### Aligning Components in MigLayout Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Specifies the alignment of components within the container when their total size does not fill the container. Supports percentage, pixel, and keyword-based alignment. ```java "align 50% 50%" ``` ```java "aligny top" ``` ```java "alignx leading" ``` ```java "align 100px" ``` ```java "top, left" ``` -------------------------------- ### Set Minimum/Maximum Component Size Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Sets the minimum or maximum size for a component along the X or Y axis. -------------------------------- ### Set Component Grow Priority Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Sets the grow priority for a component. Higher priorities grow first. Defaults to 100. ```java "growprio 50 50" "gp 110 90" "gpx 200" "growpriox 200" ``` -------------------------------- ### Layout Flow and Positioning Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Constraints for controlling how components wrap, create new lines, push, or skip cells within the layout grid. ```APIDOC ## wrap ### Description Wraps to a new column/row after the component has been put in the next available cell. ### Parameters - **gapsize** (string) - Optional - Overrides the size of the gap between the current and next row/column. ## newline ### Description Wraps to a new column/row before the component is put in the next available cell. ### Parameters - **gapsize** (string) - Optional - Overrides the size of the gap between the current and next row/column. ## push / pushx / pushy ### Description Makes the row and/or column that the component is residing in grow with a specified weight. ### Parameters - **weight** (number) - Optional - The growth weight for the row or column. ## skip ### Description Skips a number of cells in the flow before placing the component. ### Parameters - **count** (integer) - Optional - Number of cells to skip. Defaults to 1. ``` -------------------------------- ### Override Component Size with BoundSize Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Overrides the default size of a component using BoundSize expressions. Supports expressions for dynamic sizing. ```java "wmin 10" "hmax pref+100" ``` -------------------------------- ### Alignment Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Specifies how components are positioned within the container when total bounds do not fill the available space. ```text "align 50% 50%" or "aligny top" or "alignx leading" or "align 100px" or "top, left" or "aligny baseline" ``` -------------------------------- ### Size and End Group Constraints Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Groups components to share identical sizing or alignment characteristics. ```APIDOC ## sizegroup [name] ### Description Assigns a component to a size group. All components in the same group share the same BoundSize (min/preferred/max). ## endgroup [name] ### Description Assigns a component to an end group. Components in the same group align their right/bottom edges. ``` -------------------------------- ### Set Component Shrink Behavior Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Sets how a component shrinks relative to others. Defaults to a weight of 100, allowing shrinking to minimum size. ```java "shrink 50" "shrink 50 50 " ``` -------------------------------- ### Set Component Shrink Priority Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Sets the shrink priority for a component. Higher priorities shrink first when space is scarce. Defaults to 100. ```java "shrinkprio 50" "shp 200 200" "shpx 110" ``` -------------------------------- ### Set Component Grow Behavior Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/cheatsheet.html Sets how a component grows relative to others in the same cell. A weight of 0 prevents growing unless 'fill' is set. ```java "grow 50 20" "growx 50" "grow" "growx" "growy 0" ``` -------------------------------- ### Component Constraint: hidemode Source: https://github.com/mikaelgrev/miglayout/blob/master/src/site/resources/docs/whitepaper.html Defines how the layout manager handles components that are not visible. ```APIDOC ## hidemode [mode] ### Description Specifies how the layout manager handles a component that is not visible. ### Parameters - **mode** (integer) - Required - The hide mode value: - 0: Default. Invisible components are handled as if they were visible. - 1: Size of invisible component is set to 0, 0. - 2: Size and surrounding gaps of invisible component are set to 0. - 3: Invisible components do not participate in the layout at all. ### Example "hidemode 1" ```