Java JComponent Width adjustWidth(JComponent aComponent, int aWidth)

Here you can find the source of adjustWidth(JComponent aComponent, int aWidth)

Description

Adjust the size of a component such that it has the specified preferred width.

License

Open Source License

Parameter

Parameter Description
aComponent Component to be adjusted.
aWidth Value for the preferred width of the component.

Declaration

public static void adjustWidth(JComponent aComponent, int aWidth) 

Method Source Code

//package com.java2s;
/*//from   www . j a v  a 2  s.c  om
 * Copyright (c) 2006, 2007, 2008, 2010, Max Planck Institute for Informatics, Saarbruecken, Germany.
 *
 * This file is part of NetworkAnalyzer.
 * 
 * NetworkAnalyzer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 * 
 * NetworkAnalyzer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with NetworkAnalyzer. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.awt.Dimension;

import javax.swing.JComponent;

public class Main {
    /**
     * Adjust the size of a component such that it has the specified preferred width.
     * 
     * @param aComponent
     *            Component to be adjusted.
     * @param aWidth
     *            Value for the preferred width of the component.
     */
    public static void adjustWidth(JComponent aComponent, int aWidth) {
        Dimension preferedSize = aComponent.getPreferredSize();
        preferedSize.width = aWidth;
        aComponent.setPreferredSize(preferedSize);
    }
}

Related

  1. addComponent(Container container, JComponent component, int xPos, int yPos, int width, int height, double weightX, double weightY, int insetTop, int insetLeft, int insetBottom, int insetRight, int anchor, int stretch)
  2. adjustNarrowField(final JComponent component, final int width)
  3. allignBottom(JComponent lead, JComponent target, int width, int height)
  4. calculateCharWidth(JComponent component, int numChars)
  5. clearWidth(JComponent comp)
  6. clipString(final JComponent component, final String string, final int avaiableWidth)