Java Code Examples for java.awt.Component#getMinimumSize()
The following examples show how to use
java.awt.Component#getMinimumSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrappingLayout.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
public Dimension minimumLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { Dimension dim = new Dimension(0, 0); int componentCount = parent.getComponentCount(); for (int i = 0; i < componentCount; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension d = c.getMinimumSize(); dim.height = Math.max(dim.height, d.height); if (i > 0) { dim.width += hgap; } dim.width += d.width; } } Insets insets = parent.getInsets(); dim.width += insets.left + insets.right + 2 * hgap; dim.height += insets.top + insets.bottom + 2 * vgap; return dim; } }
Example 2
Source File: DimensionEncapsulation.java From hottub with GNU General Public License v2.0 | 6 votes |
public void test(final Component component) { final Dimension psize = component.getPreferredSize(); psize.width += 200; if (Objects.equals(psize, component.getPreferredSize())) { throw new RuntimeException("PreferredSize is wrong"); } final Dimension msize = component.getMaximumSize(); msize.width += 200; if (Objects.equals(msize, component.getMaximumSize())) { throw new RuntimeException("MaximumSize is wrong"); } final Dimension misize = component.getMinimumSize(); misize.width += 200; if (Objects.equals(misize, component.getMinimumSize())) { throw new RuntimeException("MinimumSize is wrong"); } }
Example 3
Source File: VerticalFlowLayout.java From Spark with Apache License 2.0 | 6 votes |
/** * Returns the minimum size needed to layout the target container. * * @param target the component to lay out. * @return the minimum layout dimension. */ @Override public Dimension minimumLayoutSize(Container target) { Dimension tarsiz = new Dimension(0, 0); for (int i = 0; i < target.getComponentCount(); i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getMinimumSize(); tarsiz.width = Math.max(tarsiz.width, d.width); if (i > 0) { tarsiz.height += vgap; } tarsiz.height += d.height; } } Insets insets = target.getInsets(); tarsiz.width += insets.left + insets.right + hgap * 2; tarsiz.height += insets.top + insets.bottom + vgap * 2; return tarsiz; }
Example 4
Source File: DimensionEncapsulation.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void test(final Component component) { final Dimension psize = component.getPreferredSize(); psize.width += 200; if (Objects.equals(psize, component.getPreferredSize())) { throw new RuntimeException("PreferredSize is wrong"); } final Dimension msize = component.getMaximumSize(); msize.width += 200; if (Objects.equals(msize, component.getMaximumSize())) { throw new RuntimeException("MaximumSize is wrong"); } final Dimension misize = component.getMinimumSize(); misize.width += 200; if (Objects.equals(misize, component.getMinimumSize())) { throw new RuntimeException("MinimumSize is wrong"); } }
Example 5
Source File: VerticalFlowLayout.java From netbeans with Apache License 2.0 | 5 votes |
private Dimension computeDimension(Container parent, int type) { Insets insets = parent.getInsets(); int x = insets.left; int y = insets.top; int columnWidth = 0; // int limitHeight = parent.getHeight() - insets.bottom; int maxY = 0; for (Component c : this.components) { if (c.isVisible()) { Dimension d; switch (type) { case 0: d = c.getPreferredSize(); break; case 1: d = c.getMinimumSize(); break; default: d = c.getMaximumSize(); break; } columnWidth = Math.max(columnWidth, d.width); /* if (limitHeight != 0 && y + d.height >= limitHeight) { x += columnWidth + this.hgap; y = insets.top; columnWidth = d.width; } */ y += d.height; maxY = Math.max(y, maxY); y += this.vgap; } } x += columnWidth; return new Dimension(x, maxY); }
Example 6
Source File: CompactLayout.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public Dimension getSize(Container parent, boolean minimum) { int n = parent.getComponentCount(); Insets insets = parent.getInsets(); Dimension d = new Dimension(); for (int i = 0; i < n; i++) { Component comp = parent.getComponent(i); if (comp instanceof EnableButton) { continue; } Dimension p = (minimum ? comp.getMinimumSize() : comp.getPreferredSize()); if (horizontal) { d.width += p.width; if (d.height < p.height) { d.height = p.height; } } else { if (d.width < p.width) { d.width = p.width; } d.height += p.height; } } d.width += (insets.left + insets.right); d.height += (insets.top + insets.bottom); return d; }
Example 7
Source File: SnapshotsWindowUI.java From netbeans with Apache License 2.0 | 5 votes |
public Dimension minimumLayoutSize(Container parent) { int minw = 0; int minh = 0; for (Component c : parent.getComponents()) { Dimension min = c.getMinimumSize(); minw += min.width; minh = Math.max(minh, min.height); } minw += HGAP * (parent.getComponentCount() - 1); return new Dimension(minw, minh); }
Example 8
Source File: BoxTabbedPaneUI.java From pumpernickel with MIT License | 5 votes |
private Dimension getLayoutSize(Container parent, boolean preferred) { int tabPlacement = ((JTabbedPane) parent).getTabPlacement(); boolean verticalPlacement = tabPlacement == JTabbedPane.TOP || tabPlacement == JTabbedPane.BOTTOM; Dimension additional = new Dimension(0, 0); Dimension max = new Dimension(0, 0); for (int a = 0; a < parent.getComponentCount(); a++) { Component c = parent.getComponent(a); Dimension d = preferred ? c.getPreferredSize() : c .getMinimumSize(); if (c instanceof UIResourcePanel) { if (verticalPlacement) { additional.height += d.height; additional.width = Math.max(additional.width, d.width); } else { additional.width += d.width; additional.height = Math.max(additional.height, d.height); } } else { max.width = Math.max(max.width, d.width); max.height = Math.max(max.height, d.height); } } if (verticalPlacement) { return new Dimension(Math.max(additional.width, max.width), additional.height + max.height); } return new Dimension(additional.width + max.width, Math.max( additional.height, max.height)); }
Example 9
Source File: CompactLayout.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public Dimension getSize(Container parent, boolean minimum) { int n = parent.getComponentCount(); Insets insets = parent.getInsets(); Dimension d = new Dimension(); for (int i = 0; i < n; i++) { Component comp = parent.getComponent(i); if (comp instanceof EnableButton) { continue; } Dimension p = (minimum ? comp.getMinimumSize() : comp.getPreferredSize()); if (horizontal) { d.width += p.width; if (d.height < p.height) { d.height = p.height; } } else { if (d.width < p.width) { d.width = p.width; } d.height += p.height; } } d.width += (insets.left + insets.right); d.height += (insets.top + insets.bottom); return d; }
Example 10
Source File: CompactLayout.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public Dimension getSize(Container parent, boolean minimum) { int n = parent.getComponentCount(); Insets insets = parent.getInsets(); Dimension d = new Dimension(); for (int i = 0; i < n; i++) { Component comp = parent.getComponent(i); if (comp instanceof EnableButton) { continue; } Dimension p = (minimum ? comp.getMinimumSize() : comp.getPreferredSize()); if (horizontal) { d.width += p.width; if (d.height < p.height) { d.height = p.height; } } else { if (d.width < p.width) { d.width = p.width; } d.height += p.height; } } d.width += (insets.left + insets.right); d.height += (insets.top + insets.bottom); return d; }
Example 11
Source File: HorizontalImagePanel.java From visualvm with GNU General Public License v2.0 | 5 votes |
@Override public Dimension getPreferredSize() { Component[] childComponents = getComponents(); if (childComponents.length == 0) { return minSize; } else { // TODO: should be computed just when child components are added/removed int minWidth = 0; for (Component component : childComponents) { int minChildComponentWidth = component.getMinimumSize().width; if (minWidth < minChildComponentWidth) minWidth = minChildComponentWidth; } return new Dimension(minWidth, imageSize.height); } }
Example 12
Source File: SwingToolkit.java From object-recognition-tensorflow with Apache License 2.0 | 4 votes |
public float getMinWidth (Component widget) { return widget.getMinimumSize().width; }
Example 13
Source File: SwingToolkit.java From tablelayout with BSD 3-Clause "New" or "Revised" License | 4 votes |
public float getMinHeight (Component widget) { return widget.getMinimumSize().height; }
Example 14
Source File: WrapLayout.java From Briss-2.0 with GNU General Public License v3.0 | 4 votes |
/** * Returns the minimum or preferred dimension needed to layout the target * container. * * @param target target to get layout size for * @param preferred should preferred size be calculated * @return the dimension to layout the target container */ private Dimension layoutSize(final Container target, final boolean preferred) { synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. // When the container width = 0, the preferred width of the // container // has not yet been calculated so lets ask for the maximum. int targetWidth = target.getSize().width; if (targetWidth == 0) { targetWidth = Integer.MAX_VALUE; } int hgap = getHgap(); int vgap = getVgap(); Insets insets = target.getInsets(); int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width Dimension dim = new Dimension(0, 0); int rowWidth = 0; int rowHeight = 0; int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. if (rowWidth + d.width > maxWidth) { addRow(dim, rowWidth, rowHeight); rowWidth = 0; rowHeight = 0; } // Add a horizontal gap for all components after the first if (rowWidth != 0) { rowWidth += hgap; } rowWidth += d.width; rowHeight = Math.max(rowHeight, d.height); } } addRow(dim, rowWidth, rowHeight); dim.width += horizontalInsetsAndGap; dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to // make sure the preferred size is less than the size of the // target containter so shrinking the container size works // correctly. Removing the horizontal gap is an easy way to do this. Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); if (scrollPane != null) { dim.width -= (hgap + 1); } return dim; } }
Example 15
Source File: WrapLayout.java From COMP3204 with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Returns the minimum or preferred dimension needed to layout the target * container. * * @param target * target to get layout size for * @param preferred * should preferred size be calculated * @return the dimension to layout the target container */ private Dimension layoutSize(Container target, boolean preferred) { synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. // When the container width = 0, the preferred width of the // container // has not yet been calculated so lets ask for the maximum. int targetWidth = target.getSize().width; if (targetWidth == 0) targetWidth = Integer.MAX_VALUE; final int hgap = getHgap(); final int vgap = getVgap(); final Insets insets = target.getInsets(); final int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); final int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width final Dimension dim = new Dimension(0, 0); int rowWidth = 0; int rowHeight = 0; final int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { final Component m = target.getComponent(i); if (m.isVisible()) { final Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. if (rowWidth + d.width > maxWidth) { addRow(dim, rowWidth, rowHeight); rowWidth = 0; rowHeight = 0; } // Add a horizontal gap for all components after the first if (rowWidth != 0) { rowWidth += hgap; } rowWidth += d.width; rowHeight = Math.max(rowHeight, d.height); } } addRow(dim, rowWidth, rowHeight); dim.width += horizontalInsetsAndGap; dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to // make sure the preferred size is less than the size of the // target containter so shrinking the container size works // correctly. Removing the horizontal gap is an easy way to do this. final Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); if (scrollPane != null && target.isValid()) { dim.width -= (hgap + 1); } return dim; } }
Example 16
Source File: WrapLayout.java From openvisualtraceroute with GNU Lesser General Public License v3.0 | 4 votes |
/** * Returns the minimum or preferred dimension needed to layout the target * container. * * @param target target to get layout size for * @param preferred should preferred size be calculated * @return the dimension to layout the target container */ private Dimension layoutSize(final Container target, final boolean preferred) { synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. // When the container width = 0, the preferred width of the container // has not yet been calculated so lets ask for the maximum. int targetWidth = target.getSize().width; if (targetWidth == 0) { targetWidth = Integer.MAX_VALUE; } final int hgap = getHgap(); final int vgap = getVgap(); final Insets insets = target.getInsets(); final int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); final int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width final Dimension dim = new Dimension(0, 0); int rowWidth = 0; int rowHeight = 0; final int nmembers = target.getComponentCount(); for (int i = 0; i < nmembers; i++) { final Component m = target.getComponent(i); if (m.isVisible()) { final Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. if (rowWidth + d.width > maxWidth) { addRow(dim, rowWidth, rowHeight); rowWidth = 0; rowHeight = 0; } // Add a horizontal gap for all components after the first if (rowWidth != 0) { rowWidth += hgap; } rowWidth += d.width; rowHeight = Math.max(rowHeight, d.height); } } addRow(dim, rowWidth, rowHeight); dim.width += horizontalInsetsAndGap; dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to // make sure the preferred size is less than the size of the // target containter so shrinking the container size works // correctly. Removing the horizontal gap is an easy way to do this. final Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); if (scrollPane != null && target.isValid()) { dim.width -= (hgap + 1); } return dim; } }
Example 17
Source File: SwingToolkit.java From gdx-texture-packer-gui with Apache License 2.0 | 4 votes |
public float getMinWidth (Component widget) { return widget.getMinimumSize().width; }
Example 18
Source File: SwingToolkit.java From object-recognition-tensorflow with Apache License 2.0 | 4 votes |
public float getMinHeight (Component widget) { return widget.getMinimumSize().height; }
Example 19
Source File: RowLayout.java From pumpernickel with MIT License | 2 votes |
/** * Returns the minimum size of a component. Subclasses are encouraged to * override this. * * @param c * the component to retrieve the minimum size. * @return the minimum size of the argument. */ protected Dimension getMinimumSize(Component c) { return c.getMinimumSize(); }
Example 20
Source File: StackLayout.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | votes |
public Dimension minimumLayoutSize(Container parent) { synchronized (parent.getTreeLock()) { int width = 0; int height = 0; for (Component comp: components) { Dimension size = comp.getMinimumSize(); width = Math.max(size.width, width); height = Math.max(size.height, height); } Insets insets = parent.getInsets(); width += insets.left + insets.right; height += insets.top + insets.bottom; return new Dimension(width, height); } }