Java JComponent Width setPreferredWidth(JComponent comp, int width)

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

Description

Sets preferred width of the component.

License

Open Source License

Parameter

Parameter Description
comp component.
width width.

Declaration

public static void setPreferredWidth(JComponent comp, int width) 

Method Source Code


//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);
    }
}

Related

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