List of usage examples for java.awt Component getPreferredSize
public Dimension getPreferredSize()
From source file:Main.java
public static void setMinimumWidth(Component c, int width) { if (c.getPreferredSize().width < width) c.setPreferredSize(new Dimension(width, c.getPreferredSize().height)); }
From source file:Main.java
public static int getPreferredHeight(Component comp) { return new Double(comp.getPreferredSize().getHeight()).intValue(); }
From source file:Main.java
public static int getPreferredWidth(Component comp) { return new Double(comp.getPreferredSize().getWidth()).intValue(); }
From source file:Main.java
/** Sets preferred width of the component, leaving the height intact. */ public static void setPreferredWidth(Component component, int width) { Dimension dim = component.getPreferredSize(); component.setPreferredSize(new Dimension(width, dim.height)); }
From source file:Main.java
public static void setPreferredWidth(Component c, int width) { c.setPreferredSize(new Dimension(width, c.getPreferredSize().height)); }
From source file:Main.java
/** * Position the given component at the center of the given parent component or physical screen. * /*ww w .ja va 2s . c o m*/ * @param c the component to be positioned * @param parent the component whose center will match the center of the given component. * If null, the given component will match the screen center. * */ public static void position(Component c, Component parent) { Dimension d = c.getPreferredSize(); if (parent == null) { Dimension s = Toolkit.getDefaultToolkit().getScreenSize(); c.setLocation(s.width / 2 - d.width / 2, s.height / 2 - d.height / 2); } else { Point p = parent.getLocationOnScreen(); int pw = parent.getWidth(); int ph = parent.getHeight(); c.setLocation(p.x + pw / 2 - d.width / 2, p.y + ph / 2 - d.height / 2); } }
From source file:Main.java
public static void setPreferredWidth(Component component, int width) { component.setPreferredSize(new Dimension(width, component.getPreferredSize().height)); }
From source file:Main.java
/** * Returns the maximum preferred size of the given components. * @param components the components/*from w w w .ja v a 2 s. c o m*/ * @return Dimension */ public static final Dimension getMaximumSize(Component... components) { Dimension size = new Dimension(); for (Component component : components) { Dimension cSize = component.getPreferredSize(); if (size.width < cSize.width) { size.width = cSize.width; } if (size.height < cSize.height) { size.height = cSize.height; } } return size; }
From source file:Main.java
public static boolean canVScroll(JViewport viewport) { JScrollPane scrollPane = (JScrollPane) viewport.getParent(); Rectangle availR = scrollPane.getBounds(); Component view = viewport.getView(); Dimension viewPrefSize = view != null ? view.getPreferredSize() : new Dimension(0, 0); Dimension extentSize = viewport.toViewCoordinates(availR.getSize()); boolean canVScroll = true; if (view instanceof Scrollable) canVScroll = !((Scrollable) view).getScrollableTracksViewportHeight(); if (canVScroll && (viewPrefSize.height <= extentSize.height)) canVScroll = false;//from w ww.jav a 2 s . c o m return canVScroll; }
From source file:Main.java
/** * Returns map of container child components preferred sizes. * * @param container// ww w .j ava 2s .com * container to process * @return map of container child components preferred sizes */ public static Map<Component, Dimension> getChildPreferredSizes(final Container container) { final int cc = container.getComponentCount(); final Map<Component, Dimension> cps = new HashMap<Component, Dimension>(cc); for (int i = 0; i < cc; i++) { final Component component = container.getComponent(i); cps.put(component, component.getPreferredSize()); } return cps; }