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 setComponentSize(JComponent comp, int width, int height) {
    comp.setPreferredSize(new Dimension(width, height));
    comp.setMinimumSize(comp.getPreferredSize());
    comp.setMaximumSize(comp.getPreferredSize());
}

From source file:Main.java

public static final void setSMPSizes(JComponent comp, Dimension d) {
    comp.setSize(d);//ww w . j a v  a  2  s.co  m
    comp.setMinimumSize(d);
    comp.setPreferredSize(d);
}

From source file:Main.java

/**
 * Set the preferred size of the given components.  Intended to reduce clutter in GUI code.
 * For Java 1.4 compatibility, the arguments must be {@code JComponent}s, not arbitrary
 * {@code Component}s.// ww  w .j ava  2 s .c  o  m
 */
public static void setPreferredSize(Dimension d, JComponent... components) {
    for (JComponent c : components) {
        c.setPreferredSize(d);
    }
}

From source file:Main.java

public static void sizeUniformly(JComponent... components) {

    for (JComponent c : components) {
        c.setPreferredSize(null);
        c.setMinimumSize(null);/*from  ww  w . j  a  v a  2s .c om*/
        c.setMaximumSize(null);
    }

    int width = 0;
    int height = 0;

    for (JComponent c : components) {
        Dimension d = c.getPreferredSize();
        if (d.width > width) {
            width = d.width;
        }
        if (d.height > height) {
            height = d.height;
        }
    }

    for (JComponent c : components) {
        Dimension d = c.getPreferredSize();
        d.width = width;
        d.height = height;
        c.setPreferredSize(d);
        c.setMinimumSize(d);
        c.setMaximumSize(d);
    }
}

From source file:Main.java

/**
 * This method encapsulates some ugly code.
 * It sets the preferred width of a component while keeping the preferred height intact.
 *//* ww  w .j  a  v  a  2s.co m*/
public static void setPreferredWidth(JComponent comp, int width) {
    Dimension preferredSize = comp.getPreferredSize();
    preferredSize.width = width;
    comp.setPreferredSize(preferredSize);
}

From source file:Main.java

/**
 * Freezes the width of the given component to the given size, preventing
 * it from expanding to fill any additional space.
 * @param component the component to freeze
 * @param width the width to freeze the component to
 * @return the component passed in, for chaining purposes
 *///from  w w w .  j  a  v  a2s  .c om
public static JComponent freezeWidth(JComponent component, int width) {
    component.setMinimumSize(new Dimension(width, component.getMinimumSize().height));
    component.setPreferredSize(new Dimension(width, component.getPreferredSize().height));
    component.setMaximumSize(new Dimension(width, component.getMaximumSize().height));
    return component;
}

From source file:Main.java

/**
 * Fixes the width of the component but maintaining it old height.
 *
 * @param comp// www . ja va2s.c om
 * @param width
 */
public static void fixWidth(JComponent comp, int width) {
    comp.setPreferredSize(new Dimension(width, comp.getPreferredSize().height));
    comp.setMaximumSize(comp.getPreferredSize());
}

From source file:Main.java

public static void forceSize(JComponent component, int width, int height) {
    Dimension d = new Dimension(width, height);
    component.setMinimumSize(d);//from  w w w  .j  a  v a2  s .  co  m
    component.setMaximumSize(d);
    component.setPreferredSize(d);
}

From source file:Main.java

public static void sizeIt(JComponent c, int width, int height) {
    if (height < 0) {
        height = c.getPreferredSize().height;
    }//from ww  w.  j  a v  a 2s.c  om
    Dimension myDimension = new Dimension(width, height);
    c.setMaximumSize(myDimension);
    c.setMinimumSize(myDimension);
    c.setPreferredSize(myDimension);
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

public static JComponent createTitledPanel(JComponent component, String title, int width, int height) {
    component.setPreferredSize(new Dimension(width, height));
    component.setMinimumSize(new Dimension(width, height));
    return createTitledPanel(component, title);
}