List of utility methods to do JComponent Size
void | makeSameSize(JComponent... comps) Makes all Compontens the same Size if (comps.length == 0) { return; int max = 0; for (JComponent comp1 : comps) { int w = comp1.getPreferredSize().width; max = w > max ? w : max; Dimension dim = new Dimension(max, comps[0].getPreferredSize().height); for (JComponent comp : comps) { comp.setPreferredSize(dim); |
void | makeSameSize(JComponent[] comps) make Same Size if (comps.length == 0) { return; int max = 0; for (int i = 0; i < comps.length; i++) { int w = comps[i].getPreferredSize().width; max = w > max ? w : max; Dimension dim = new Dimension(max, comps[0].getPreferredSize().height); for (int i = 0; i < comps.length; i++) { comps[i].setPreferredSize(dim); |
T | minSize(T comp, int width) Sets the minimum size of the JComponent if (comp == null) { return null; comp.setMinimumSize(new Dimension(width, comp.getMinimumSize().height)); return comp; |
BufferedImage | paint(final Component c, Dimension size) Paint a Component as a BufferedImage using its preferred size. if (size == null) size = c.getPreferredSize(); final BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); try { Runnable runnable1 = new Runnable() { private void revalidate(Component c) { if (c instanceof Container) { Container c2 = (Container) c; ... |
Dimension | preferredSize(JComponent component) preferred Size Dimension size = component.getPreferredSize();
component.setSize(size);
return size;
|
void | resize(JComponent component, Dimension size) resize component.setPreferredSize(size); component.setMaximumSize(size); component.setMinimumSize(size); |
void | resizeComponentWidth(JComponent currentComponent, double maxComponentWidth) resize Component Width currentComponent.setPreferredSize( new Dimension((int) maxComponentWidth, (int) currentComponent.getPreferredSize().getHeight())); currentComponent.setMaximumSize( new Dimension((int) maxComponentWidth, (int) currentComponent.getMaximumSize().getHeight())); currentComponent.setMinimumSize( new Dimension((int) maxComponentWidth, (int) currentComponent.getMinimumSize().getHeight())); |
void | restrictWindowMinimumSize(final Window wnd, final Dimension minSize) Adds listener to window that ensures that the window is not resized less then specified size. restrictMinimumSizeImpl(wnd, minSize); |
Dimension | sameSize(JComponent[] components) same Size int width = 0; int height = 0; for (int i = 0; i < components.length; i++) { Dimension size = components[i].getPreferredSize(); width = Math.max(width, size.width); height = Math.max(height, size.height); Dimension result = new Dimension(width, height); ... |
void | saveComponentSize(JComponent comp, Preferences prefs, String name) Save the size of a JComponent to a package Preferences object. Dimension dims = null; if (comp instanceof JViewport) { dims = ((JViewport) comp).getExtentSize(); } else { dims = comp.getSize(); prefs.putInt(name + "_width", dims.width); prefs.putInt(name + "_height", dims.height); ... |