Example usage for javax.swing JComponent setPreferredSize

List of usage examples for javax.swing JComponent setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JComponent setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:Main.java

public static void setPreferredWidth(JComponent component, int width) {
    component.setPreferredSize(new Dimension(width, component.getPreferredSize().height));
}

From source file:Main.java

public static void setComponentSize(int width, int height, JComponent l) {
    l.setPreferredSize(new Dimension(width, height));
    l.setMinimumSize(new Dimension(width, height));
    if (l instanceof JTextField || l instanceof JComboBox) {
        l.setMaximumSize(new Dimension(Short.MAX_VALUE, height));
    }//from  w ww. ja  v a2 s .  c  om
}

From source file:Main.java

public static void setMaxPreferredSize(JComponent comp) {
    comp.setPreferredSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
}

From source file:Main.java

/**
 * Fixes the height of the component but maintaining it old width.
 *
 * @param comp//from ww  w.  j  a  va  2 s .c o  m
 * @param height
 */
public static void fixHeight(JComponent comp, int height) {
    comp.setPreferredSize(new Dimension(comp.getPreferredSize().width, height));
}

From source file:Main.java

public static void setFixedSize(JComponent component, Dimension size) {
    component.setPreferredSize(size);
    component.setMinimumSize(size);/*from w  w w. j  av  a 2s  .c  o  m*/
    component.setMaximumSize(size);
    component.setSize(size);
}

From source file:Main.java

public static void set3Dimensions(JComponent c, Dimension d) {
    c.setMinimumSize(d);/*from ww w  .j a v a  2 s  .  com*/
    c.setPreferredSize(d);
    c.setMaximumSize(d);
}

From source file:Main.java

public static void setPreferredWidth(JComponent component, int width) {

    component.setPreferredSize(new Dimension(width, (int) component.getPreferredSize().getHeight()));
}

From source file:Main.java

/**
 * Sets the preferred height of the specified component.
 *
 * @param component//  w  w  w .  java 2 s .  com
 *            The component
 * @param height
 *            The preferred height
 */

public static void setPreferredHeight(final JComponent component, final int height) {
    component.setPreferredSize(new Dimension(component.getPreferredSize().width, height));
}

From source file:Main.java

public static void setPreferredHeight(JComponent component, int height) {

    component.setPreferredSize(new Dimension((int) component.getPreferredSize().getWidth(), height));
}

From source file:Main.java

private static void setSizes(java.util.List<JComponent> aComponents, Dimension aDimension) {
    Iterator<JComponent> compsIter = aComponents.iterator();
    while (compsIter.hasNext()) {
        JComponent comp = (JComponent) compsIter.next();
        comp.setPreferredSize((Dimension) aDimension.clone());
        comp.setMaximumSize((Dimension) aDimension.clone());
    }//from  w w  w  . j av a  2s. com
}