Java JComponent Width setComponentWidth(final JComponent component, final int width)

Here you can find the source of setComponentWidth(final JComponent component, final int width)

Description

Adjust the width of the specified component.

License

Open Source License

Parameter

Parameter Description
component a parameter
width a parameter

Declaration


public static void setComponentWidth(final JComponent component, final int width) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import javax.swing.*;

import java.awt.*;

public class Main {
    public static final int HEIGHT_ROW = 27;

    /***********************************************************************************************
     * Adjust the width of the specified component.
     */*from  w  w w. j  av a 2s.  c  o m*/
     * @param component
     * @param width
     */

    public static void setComponentWidth(final JComponent component, final int width) {
        if ((component != null) && (width > 0)) {
            component.setMaximumSize(new Dimension(width, HEIGHT_ROW));
            component.setPreferredSize(new Dimension(width, HEIGHT_ROW));
        }
    }
}

Related

  1. makeSamePreferredWidth(JComponent... comps)
  2. normalizeWidth(JComponent... components)
  3. sameWidth(JComponent[] components, int width)
  4. setBoundsAndCenterHorizontally(JComponent component, int x, int y, int width, int height)
  5. setComponent3Width(JComponent c, int width)
  6. setMaximumWidth(final JComponent component, final int width)
  7. setMaximumWidth(JComponent component, int width)
  8. setMaxWidth(JComponent comp, int width)
  9. setMinimumWidth(JComponent component, int minWidth)