Here you can find the source of setPreferredWidth(JComponent comp, int width)
Parameter | Description |
---|---|
comp | component. |
width | width. |
public static void setPreferredWidth(JComponent comp, int width)
//package com.java2s; // the terms of the GNU General Public License as published by the Free Software Foundation; import javax.swing.*; import java.awt.*; public class Main { /**//from w ww. j a va 2s. c om * Sets preferred width of the component. * * @param comp component. * @param width width. */ public static void setPreferredWidth(JComponent comp, int width) { Dimension size = comp.getPreferredSize(); size.width = width; comp.setPreferredSize(size); } }