Java JComponent Width setPreferredWidth(JComponent component, int width)

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

Description

set Preferred Width

License

Apache License

Declaration

public static void setPreferredWidth(JComponent component, int width) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Dimension;

import javax.swing.JComponent;

public class Main {
    public static void setPreferredWidth(JComponent component, int width) {
        component.setPreferredSize(getPreferredSize(component, width));
    }//from   w  w w.j  a v a 2  s . c o m

    /**
     * Returns the preferred dimensions of a component, using the current height
     * and a custom width.
     * @param component The component providing the preferred height.
     * @param width The preferred width.
     * @return The preferred dimension.
     */
    public static Dimension getPreferredSize(JComponent component, int width) {
        Dimension dim = component.getPreferredSize();
        return new Dimension(width, dim.height);
    }
}

Related

  1. setPreferredWidth(JComponent comp, int iWidth)
  2. setPreferredWidth(JComponent comp, int width)
  3. setPreferredWidth(JComponent comp, int width)
  4. setPreferredWidth(JComponent component, int width)
  5. setPreferredWidth(JComponent component, int width)
  6. setPrefferedWidth(JComponent c, int w)
  7. setZeroWidth(JComponent comp)
  8. toFixedDim(JComponent c, int width, int height)