Java Utililty Methods JComponent Width

List of utility methods to do JComponent Width

Description

The list of methods to do JComponent Width are organized into topic(s).

Method

voidsetComponentWidth(final JComponent component, final int width)
Adjust the width of the specified component.
if ((component != null) && (width > 0)) {
    component.setMaximumSize(new Dimension(width, HEIGHT_ROW));
    component.setPreferredSize(new Dimension(width, HEIGHT_ROW));
voidsetMaximumWidth(final JComponent component, final int width)
set Maximum Width
final Dimension preferredSize = component.getPreferredSize();
final Dimension size = new Dimension(width, preferredSize.height);
component.setMaximumSize(size);
voidsetMaximumWidth(JComponent component, int width)
set Maximum Width
component.setMaximumSize(new Dimension(width, (int) component.getMaximumSize().getHeight()));
voidsetMaxWidth(JComponent comp, int width)
set Max Width
comp.setMaximumSize(new Dimension(width, Short.MAX_VALUE));
voidsetMinimumWidth(JComponent component, int minWidth)
set Minimum Width
Dimension dim = component.getMinimumSize();
dim = new Dimension(minWidth, dim.height);
component.setMinimumSize(dim);
voidsetMinimumWidth(JComponent component, int width)
set Minimum Width
component.setMinimumSize(new Dimension(width, component.getMinimumSize().height));
voidsetPreferredWidth(final JComponent component, final int width)
Sets the preferred width of the specified component.
component.setPreferredSize(new Dimension(width, component.getPreferredSize().height));
voidsetPreferredWidth(final JComponent component, final int width)
Sets the width of a JComponent without changing its height.
final int height = (int) component.getPreferredSize().getHeight();
component.setPreferredSize(new Dimension(width, height));
voidsetPreferredWidth(int width, JComponent... components)
Sets all specified components to the same width.
for (JComponent component : components) {
    component.setPreferredSize(new Dimension(width, component.getPreferredSize().height));
voidsetPreferredWidth(JComponent comp, int iWidth)
sets the preferred width of the given component (without changing its preferred height).
comp.setPreferredSize(new Dimension(iWidth, getPreferredHeight(comp)));