public void layoutContainer(Canvas canvas, int[] bounds) { for (ComponentWrapper wrapper : children) { if (wrapper instanceof MigLayout) { MigLayout layout = (MigLayout) wrapper; layout.layoutContainer(canvas, bounds); } else if (wrapper instanceof MigComponent) { MigComponent migComponent = (MigComponent) wrapper; migComponent.calculatePreferredSize(canvas, canvas.size()); } } checkCache(); if (grid.layout(bounds, lc.getAlignX(), lc.getAlignY(), debug, true)) { grid = null; checkCache(); grid.layout(bounds, lc.getAlignX(), lc.getAlignY(), debug, false); } }
if (lc.isFlowX() == false) sb.append(asAPI ? ".flowY()" : ",flowy"); boolean fillX = lc.isFillX(); boolean fillY = lc.isFillY(); if (fillX || fillY) { if (fillX == fillY) { Boolean leftToRight = lc.getLeftToRight(); if (leftToRight != null) { if (asAPI) { if (!lc.getPackWidth().isUnset() || !lc.getPackHeight().isUnset()) { if (asAPI) { String w = getBS(lc.getPackWidth()); String h = getBS(lc.getPackHeight()); sb.append(".pack("); if (w.equals("pref") && h.equals("pref")) { String size = getBS(lc.getPackWidth()) + " " + getBS(lc.getPackHeight()); if (size.equals("pref pref") == false) sb.append(' ').append(size); if (lc.getPackWidthAlign() != 0.5f || lc.getPackHeightAlign() != 1f) { if (asAPI) { sb.append(".packAlign(").append(floatToString(lc.getPackWidthAlign(), asAPI)).append(", ").append(floatToString(lc.getPackHeightAlign(), asAPI)).append(')'); } else { sb.append(",packalign ").append(floatToString(lc.getPackWidthAlign(), asAPI)).append(' ').append(floatToString(lc.getPackHeightAlign(), asAPI));
LC lc = new LC(); if (s.isEmpty()) return lc; if (len == 3 || len == 11) { // Optimization if (part.equals("ltr") || part.equals("rtl") || part.equals("lefttoright") || part.equals("righttoleft")) { lc.setLeftToRight(part.charAt(0) == 'l' ? Boolean.TRUE : Boolean.FALSE); lc.setTopToBottom(part.charAt(0) == 't'); if (ix > -1) { String num = part.substring(ix).trim(); lc.setWrapAfter(num.length() != 0 ? Integer.parseInt(num) : 0); continue; if (isHor && (part.startsWith("w ") || part.startsWith("width "))) { String sz = part.substring(part.charAt(1) == ' ' ? 2 : 6).trim(); lc.setWidth(parseBoundSize(sz, false, true)); continue; lc.setHeight(parseBoundSize(uvStr, false, false)); continue; String sz = part.substring(5).trim(); if (part.startsWith("wmin ")) { lc.minWidth(sz); continue; } else if (part.startsWith("wmax ")) { lc.maxWidth(sz);
public static void main(String[] args) { JPanel panel1 = new JPanel(new MigLayout(new LC().fill())); panel1.add(new JTextField("text1"), "span, growx"); panel1.add(new JTextField("another text field"), "span, growx"); panel1.add(new JTextField("text3"), "span, growx"); JPanel panel2 = new JPanel(new MigLayout()); JTextArea textArea = new JTextArea(); textArea.setColumns(15); textArea.setRows(7); JScrollPane jsp = new JScrollPane(textArea); panel2.add(jsp, "span, grow"); JFrame frame = new JFrame(); frame.setLayout(new GridLayout(1, 2)); frame.add(panel1); frame.add(panel2); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
BoundSize wBounds = lc.getPackWidth(); BoundSize hBounds = lc.getPackHeight(); int x = Math.round(p.x - ((targW - packable.getWidth()) * (1 - lc.getPackWidthAlign()))); int y = Math.round(p.y - ((targH - packable.getHeight()) * (1 - lc.getPackHeightAlign())));
LC layoutConstraints = new LC(); layoutConstraints.setFillX(true); layoutConstraints.setDebugMillis(500); super.setLayout(new MigLayout(layoutConstraints);
LC lc_Y = (new LC()).fill().flowY(); lc_Y.setWrapAfter(ITEMS_PER_COLUMN); JPanel panel = new JPanel(new MigLayout(lc_Y));
cPnl = new JPanel(); rPnl = new JPanel(); lPnl.setLayout(new MigLayout(new LC().fillY())); lPnl.add(enabledModsLbl, GuiConstants.WRAP); lPnl.add(enabledModsScl, "pushy, " + GuiConstants.GROW + GuiConstants.SEP + GuiConstants.WRAP); cPnl.add(enableMod, GuiConstants.WRAP); cPnl.add(disableMod); rPnl.setLayout(new MigLayout(new LC().fillY())); rPnl.add(disabledModsLbl, GuiConstants.WRAP); rPnl.add(disabledModsScl, "pushy, " + GuiConstants.GROW + GuiConstants.SEP + GuiConstants.WRAP); rPnl.add(addMod, GuiConstants.FILL_SINGLE_LINE); formPnl.setLayout(new MigLayout(new LC().fillY())); formPnl.add(lPnl, "push, grow, " + GuiConstants.SPLIT_3); formPnl.add(cPnl, "push, grow, center");
/** Returns the debug millis. Combines the value from {@link net.miginfocom.layout.LC#getDebugMillis()} and {@link net.miginfocom.layout.LayoutUtil#getGlobalDebugMillis()} * @return The combined value. */ private int getDebugMillis() { int globalDebugMillis = LayoutUtil.getGlobalDebugMillis(); return globalDebugMillis > 0 ? globalDebugMillis : lc.getDebugMillis(); }
JButton closeButton = new JButton("Close"); JButton mainMenuButton = new JButton("Menu"); JLabel labelTitle = new JLabel("Application"); JPanel panel = new JPanel(); panel.setLayout(new MigLayout(new LC().fillX())); panel.add(labelTitle, new CC().alignX("center").spanX()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new MigLayout(new LC().fillX())); buttonPanel.add(closeButton, new CC().alignX("right").split()); buttonPanel.add(mainMenuButton, new CC().alignX("right")); buttonPanel.setOpaque(false); JXLayer<JPanel> mainPanel = new JXLayer<JPanel>(); mainPanel.setView(panel); mainPanel.setGlassPane(buttonPanel); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(mainPanel); frame.setSize(400, 600); frame.setVisible(true);