List of utility methods to do JComponent Size
void | equalizeSize(final JComponent... components) Resizes the given components making them equal in size. if (components == null || components.length == 0) return; final Dimension prefSize = components[0].getPreferredSize(); final Dimension maxSize = components[0].getMaximumSize(); for (JComponent c : components) { ensureSize(prefSize, c.getPreferredSize()); ensureSize(maxSize, c.getMaximumSize()); for (JComponent c : components) { c.setPreferredSize(prefSize); c.setMaximumSize(maxSize); |
void | equalizeSizes(JComponent[] components) Sets the items in aComponents to the same size.
Dimension targetSize = new Dimension(0, 0); for (int i = 0; i < components.length; i++) { JComponent comp = components[i]; Dimension compSize = comp.getPreferredSize(); double width = Math.max(targetSize.getWidth(), compSize.getWidth()); double height = Math.max(targetSize.getHeight(), compSize.getHeight()); targetSize.setSize(width, height); setSizes(components, targetSize); |
void | evenSizes(JComponent[] components) Makes all sizes (min, pref, max) the same to the respective maximum of all given components. Dimension minSize = new Dimension(Integer.MIN_VALUE, Integer.MIN_VALUE); Dimension prefSize = new Dimension(Integer.MIN_VALUE, Integer.MIN_VALUE); Dimension maxSize = new Dimension(Integer.MIN_VALUE, Integer.MIN_VALUE); for (int i = 0; i < components.length; i++) { Dimension min = components[i].getMinimumSize(); if (min.width > minSize.width) minSize.width = min.width; if (min.height > minSize.height) ... |
Rectangle | findCenterBounds(Dimension componentSize) Helps client code place components on the center of the screen. return findCenterBounds(getCurrentGraphicsConfiguration(), componentSize);
|
void | fixSize(JComponent c, Dimension d) fix Size c.setMaximumSize(d); c.setPreferredSize(d); c.setMaximumSize(d); c.revalidate(); |
void | fixSize(JComponent... items) fix Size for (JComponent item : items) {
item.setMinimumSize(item.getPreferredSize());
item.setMaximumSize(item.getPreferredSize());
item.setSize(item.getPreferredSize());
|
T | fixSize(T comp, int width) Fixes the size of a JComponent to the given width If a value of -1 is passed along, the preferred size is used instead. return fixSize(comp, width, -1);
|
void | forceSize(JComponent component, int width, int height) force Size Dimension d = new Dimension(width, height);
component.setMinimumSize(d);
component.setMaximumSize(d);
component.setPreferredSize(d);
|
JComponent | freezeSize(JComponent c, Dimension s) freeze Size c.validate();
c.setMinimumSize(s);
c.setMaximumSize(s);
c.setPreferredSize(s);
return c;
|
Rectangle | getCentralLocation(Component sourceComp, Component comp, Dimension size) get Central Location final Rectangle position; if (sourceComp != null) { Point compLocation = new Point(0, 0); SwingUtilities.convertPointToScreen(compLocation, sourceComp); GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = e.getScreenDevices(); Rectangle displayBounds = null; for (GraphicsDevice device : devices) { ... |