Java JComponent Width setPreferredWidth(JComponent comp, int iWidth)

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

Description

sets the preferred width of the given component (without changing its preferred height).

License

Open Source License

Parameter

Parameter Description
comp a parameter
iWidth a parameter

Declaration

public static void setPreferredWidth(JComponent comp, int iWidth) 

Method Source Code

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

Related

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