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

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

Description

Sets the preferred width of the specified component.

License

Open Source License

Parameter

Parameter Description
component The component
width The preferred width

Declaration

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

Method Source Code

//package com.java2s;
/*//  ww  w .jav  a  2  s. co  m
 * Copyright (C) 2010-2012 Klaus Reimer <k@ailis.de>
 * See LICENSE.TXT for licensing information.
 */

import java.awt.Dimension;

import javax.swing.JComponent;

public class Main {
    /**
     * Sets the preferred width of the specified component.
     * 
     * @param component
     *            The component
     * @param width
     *            The preferred width
     */
    public static void setPreferredWidth(final JComponent component, final int width) {
        component.setPreferredSize(new Dimension(width, component.getPreferredSize().height));
    }
}

Related

  1. setMaximumWidth(JComponent component, int width)
  2. setMaxWidth(JComponent comp, int width)
  3. setMinimumWidth(JComponent component, int minWidth)
  4. setMinimumWidth(JComponent component, int width)
  5. setPreferredWidth(final JComponent component, final int width)
  6. setPreferredWidth(int width, JComponent... components)
  7. setPreferredWidth(JComponent comp, int iWidth)
  8. setPreferredWidth(JComponent comp, int width)
  9. setPreferredWidth(JComponent comp, int width)