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

Open Source License

Declaration

public static void setPreferredWidth(JComponent component, int width) 

Method Source Code

//package com.java2s;
/***************************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License 3 as published by
the Free Software Foundation./*www. j av a  2  s .c  o m*/
    
This program 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
General Public License for more details.
 ***************************************************************************/

import java.awt.*;
import javax.swing.*;

public class Main {
    public static void setPreferredWidth(JComponent component, int width) {
        Dimension d = component.getPreferredSize();
        d.width = width;
        component.setPreferredSize(d);
    }
}

Related

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