List of usage examples for java.awt Component getMaximumSize
public Dimension getMaximumSize()
From source file:Main.java
/** Sets maximum width of the component, leaving the height intact. */ public static void setMaximumWidth(Component component, int width) { Dimension dim = component.getMaximumSize(); component.setMaximumSize(new Dimension(width, dim.height)); }
From source file:SpringBox.java
/** * A debugging utility that prints to stdout the component's minimum, * preferred, and maximum sizes./* w w w . j av a 2 s . co m*/ */ public static void printSizes(Component c) { System.out.println("minimumSize = " + c.getMinimumSize()); System.out.println("preferredSize = " + c.getPreferredSize()); System.out.println("maximumSize = " + c.getMaximumSize()); }
From source file:Main.java
public static Dimension getSize(Component c, int sizeflag) { if (c == null) { return new Dimension(0, 0); }/*from w w w.j a va 2 s . c o m*/ //special case due to swing bug: html labels need to know the current parent layout's size if (c instanceof JLabel) { View v = (View) ((JLabel) c).getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey); if (v != null) { switch (sizeflag) { case MIN: { Dimension d = new Dimension(c.getPreferredSize()); d.width = 1; return d; } case PREF: { Dimension d = new Dimension(c.getPreferredSize()); return d; } case MAX: { Dimension d = new Dimension(10240, 10240); d.width = 1; return d; } } } } // switch (sizeflag) { case MIN: { return new Dimension(c.getMinimumSize()); } case PREF: { return new Dimension(c.getPreferredSize()); } case MAX: { return new Dimension(c.getMaximumSize()); } } return new Dimension(c.getPreferredSize()); }
From source file:ColumnLayout.java
protected Dimension layoutSize(Container parent, int sizetype) { int nkids = parent.getComponentCount(); Dimension size = new Dimension(0, 0); Insets insets = parent.getInsets(); int num_visible_kids = 0; // Compute maximum width and total height of all visible kids for (int i = 0; i < nkids; i++) { Component kid = parent.getComponent(i); Dimension d;// w w w. j av a 2 s . c o m if (!kid.isVisible()) continue; num_visible_kids++; if (sizetype == 1) d = kid.getPreferredSize(); else if (sizetype == 2) d = kid.getMinimumSize(); else d = kid.getMaximumSize(); if (d.width > size.width) size.width = d.width; size.height += d.height; } // Now add in margins and stuff size.width += insets.left + insets.right + 2 * margin_width; size.height += insets.top + insets.bottom + 2 * margin_height; if (num_visible_kids > 1) size.height += (num_visible_kids - 1) * spacing; return size; }
From source file:org.jdal.swing.form.SimpleBoxFormBuilder.java
/** * Add a component to Form at position pointer by cursor, * Increments cursor by one./*from w w w . j a v a 2s . com*/ * @param c Component to add */ public void add(Component c) { if (debug) { if (c instanceof JComponent) ((JComponent) c).setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); } addBox(c); if (rowHeight < Short.MAX_VALUE) { Dimension d = c.getPreferredSize(); d.height = rowHeight; c.setPreferredSize(d); c.setMinimumSize(d); if (!c.isMaximumSizeSet() || c.getMaximumSize().getHeight() > rowHeight) { c.setMaximumSize(new Dimension(Short.MAX_VALUE, rowHeight)); } } }
From source file:TableLayout.java
/** * Lays out the specified container. Throws an * <code>IllegalStateException</code> if any of the components added via the * <code>addLayoutComponent</code> method have a different parent than the * specified Container.// ww w . j a va 2 s . co m */ public void layoutContainer(Container parent) { synchronized (parent.getTreeLock()) { int rowCount = rows.size(); Insets parentInsets = parent.getInsets(); // Collect the preferred sizes. Dimension[][] prefSizes = getPreferredSizes(parent); Pair layout = calculateLayout(prefSizes); int[] columnWidths = (int[]) layout.getFirst(); int[] rowHeights = (int[]) layout.getSecond(); Dimension prefParentSize = calculatePreferredLayoutSize(parent, columnWidths, rowHeights); Dimension parentSize = parent.getSize(); Dimension layoutSize = new Dimension( parentSize.width - xGap * (rowCount - 1) - parentInsets.left - parentInsets.right, parentSize.height - yGap * (columnCount - 1) - parentInsets.top - parentInsets.bottom); Dimension prefLayoutSize = new Dimension( prefParentSize.width - xGap * (rowCount - 1) - parentInsets.left - parentInsets.right, prefParentSize.height - yGap * (columnCount - 1) - parentInsets.top - parentInsets.bottom); // Layout the components. int y = parentInsets.top; for (int i = 0; i < rowCount; i++) { int x = parentInsets.left; int cellHeight = (rowHeights[i] * layoutSize.height) / prefLayoutSize.height; Component[] row = (Component[]) rows.elementAt(i); for (int j = 0; j < row.length; j++) { int cellWidth = (columnWidths[j] * layoutSize.width) / prefLayoutSize.width; Component component = row[j]; // Can only happen on the last line when all the remaining components are null as well if (component == null) break; Dimension maxSize = component.getMaximumSize(); int compWidth = Math.min(maxSize.width, cellWidth); int compHeight = Math.min(maxSize.height, cellHeight); int compX = x + (int) ((cellWidth - compWidth) * component.getAlignmentX()); int compY = y + (int) ((cellHeight - compHeight) * component.getAlignmentY()); component.setBounds(compX, compY, compWidth, compHeight); x += cellWidth + xGap; } y += cellHeight + yGap; } } }
From source file:org.kineticsystem.commons.layout.TetrisLayout.java
/** * Add the specified component to the layout, using the specified * constraint object.//from www .j a v a 2s. co m * @param comp The component to be added * @param constraints Where/how the component is added to the layout. */ public void addLayoutComponent(Component comp, Object constraints) { if (constraints == null) { constraints = new Cell(); } if (constraints instanceof Cell) { Cell cell = (Cell) constraints; if (cell.getRows() < 0 || cell.getCols() < 0) { logger.fatal("Cannot add to layout: " + "cell must have positive row and column number!"); System.exit(TetrisLayout.FATAL_ERROR); } setConstraints(comp, cell); // Store a copy of all component dimensions. Size cd = new Size(); cd.setMaximumWidth(comp.getMaximumSize().getWidth()); cd.setMaximumHeight(comp.getMaximumSize().getHeight()); cd.setMinimumWidth(comp.getMinimumSize().getWidth()); cd.setMinimumHeight(comp.getMinimumSize().getHeight()); cd.setPreferredWidth(comp.getPreferredSize().getWidth()); cd.setPreferredHeight(comp.getPreferredSize().getHeight()); // Check dimensions. if (cd.getMinimumWidth() > cd.getPreferredWidth()) { logger.warn("Component minimum width is greater than preferred" + " width: set value to preferred size!\n" + cd); cd.setMinimumWidth(cd.getPreferredWidth()); } if (cd.getMaximumWidth() < cd.getPreferredWidth()) { logger.warn("Component maximum width is less than preferred" + " width: set value to preferred size!\n" + cd); cd.setMaximumWidth(cd.getPreferredWidth()); } if (cd.getMinimumHeight() > cd.getPreferredHeight()) { logger.warn("Component minimum height is greater than preferred" + " height: set value to preferred size!\n" + cd); cd.setMinimumHeight(cd.getPreferredHeight()); } if (cd.getMaximumHeight() < cd.getPreferredHeight()) { logger.warn("Component maximum height is less than preferred" + " height: set value to preferred size!\n" + cd); cd.setMaximumHeight(cd.getPreferredHeight()); } componentSizes.put(comp, cd); } else if (constraints != null) { logger.fatal("Cannot add to layout: constraint must be a Cell!"); System.exit(TetrisLayout.FATAL_ERROR); } }