List of utility methods to do JComponent Width
int | getMinimumWidth(JComponent comp) get Minimum Width return comp.getMinimumSize().width;
|
Rectangle | getRectangle(JComponent comp) Get a Rectangle object representing the given JComponent's position and magnitude in space.
return new Rectangle(comp.getY(), comp.getX(), comp.getWidth(), comp.getHeight()); |
Rectangle | getRectangle(JComponent comp) Get a Rectangle object representing the given JComponent's position and magnitude in space.
Rectangle Rectangle = new Rectangle(comp.getY(), comp.getX(), comp.getWidth(), comp.getHeight()); return Rectangle; |
void | initComponent(JComponent component, String title, int width, int height) init Component component.setPreferredSize(new Dimension(width, height)); component.setMinimumSize(new Dimension(width, height)); component.setBorder(BorderFactory.createTitledBorder(title)); |
void | makeEqualWidth(JComponent... components) Sets the minimum width of all components to the width of the widest component. int maxSize = 0; for (JComponent comp : components) { Dimension size = comp.getPreferredSize(); if (size.width > maxSize) { maxSize = size.width; for (JComponent comp : components) { ... |
void | makeSamePreferredWidth(JComponent... comps) Makes components use same width as the width of the widest component in the group if (comps.length == 0) return; Arrays.sort(comps, new Comparator<JComponent>() { @Override public int compare(JComponent o1, JComponent o2) { return o1.getPreferredSize().width - o2.getPreferredSize().width; }); ... |
void | normalizeWidth(JComponent... components) Sets all specified components to the same width. int width = 0; for (JComponent component : components) { if (component.getPreferredSize().width > width) { width = component.getPreferredSize().width; setPreferredWidth(width, components); |
void | sameWidth(JComponent[] components, int width) same Width for (int i = 0; i < components.length; i++) { Dimension size = components[i].getSize(); size.width = width; components[i].setSize(size); |
void | setBoundsAndCenterHorizontally(JComponent component, int x, int y, int width, int height) set Bounds And Center Horizontally Container parent = component.getParent(); int parentWidth = parent.getWidth(); int paddingOnBothSides = parentWidth - width; x = paddingOnBothSides / 2; component.setBounds(x, y, width, height); |
void | setComponent3Width(JComponent c, int width) set Component Width Dimension d = new Dimension(width, c.getPreferredSize().height);
set3Dimensions(c, d);
|