Here you can find the source of setPreferredWidth(JComponent comp, int iWidth)
Parameter | Description |
---|---|
comp | a parameter |
iWidth | a parameter |
public static void setPreferredWidth(JComponent comp, int iWidth)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.awt.Dimension; import javax.swing.JComponent; public class Main { /**// w w w . j ava 2 s . co m * sets the preferred width of the given component (without changing its preferred height). * @param comp * @param iWidth */ public static void setPreferredWidth(JComponent comp, int iWidth) { comp.setPreferredSize(new Dimension(iWidth, getPreferredHeight(comp))); } /** * @param comp * @return comp.getPreferredSize().height */ public static int getPreferredHeight(JComponent comp) { return comp.getPreferredSize().height; } }