Java JComponent Size getPreferredSize(JComponent component, int width)

Here you can find the source of getPreferredSize(JComponent component, int width)

Description

Returns the preferred dimensions of a component, using the current height and a custom width.

License

Apache License

Parameter

Parameter Description
component The component providing the preferred height.
width The preferred width.

Return

The preferred dimension.

Declaration

public static Dimension getPreferredSize(JComponent component, int width) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Dimension;

import javax.swing.JComponent;

public class Main {
    /**/*from  w  w w  .  j  a  v  a  2 s.co  m*/
     * Returns the preferred dimensions of a component, using the current height
     * and a custom width.
     * @param component The component providing the preferred height.
     * @param width The preferred width.
     * @return The preferred dimension.
     */
    public static Dimension getPreferredSize(JComponent component, int width) {
        Dimension dim = component.getPreferredSize();
        return new Dimension(width, dim.height);
    }
}

Related

  1. getCentralLocation(Component sourceComp, Component comp, Dimension size)
  2. getComponentOfSameSize(final JComponent c)
  3. getLocalScreenSize(Component invoker)
  4. getMaxSize(JComponent[] components)
  5. getOptimalScreenSize(Container container, Dimension currentDim)
  6. getPreferredSize(String html, boolean width, int prefSize)
  7. getPreferredSize(Window window)
  8. getPreferredSizeComponent(JComponent component)
  9. getScreenSize()