Example usage for java.awt Component setPreferredSize

List of usage examples for java.awt Component setPreferredSize

Introduction

In this page you can find the example usage for java.awt Component setPreferredSize.

Prototype

public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component to a constant value.

Usage

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static void showInfo(Component parent, String message) {
    Component cmp = new JScrollPane(new JTextArea(message));
    cmp.setPreferredSize(new Dimension(400, 400));
    JOptionPane.showMessageDialog(parent, cmp, "Information", JOptionPane.INFORMATION_MESSAGE);
}

From source file:Main.java

public static void setSizes(Component comp, Dimension dim) {
    comp.setMinimumSize(dim);/*from   w  w  w .  j  a  v  a  2  s  .c o  m*/
    comp.setPreferredSize(dim);
    comp.setMaximumSize(new Dimension(Short.MAX_VALUE, (int) comp.getPreferredSize().getHeight()));
}

From source file:Main.java

public static void setMinimumWidth(Component c, int width) {
    if (c.getPreferredSize().width < width)
        c.setPreferredSize(new Dimension(width, c.getPreferredSize().height));
}

From source file:Main.java

public static void setForcedSize(Component comp, Dimension dim) {
    comp.setMinimumSize(dim);//from   w w w  . j a  v a 2 s  .  c o  m
    comp.setPreferredSize(dim);
    comp.setMaximumSize(dim);
}

From source file:Main.java

/** Sets preferred width of the component, leaving the height intact. */
public static void setPreferredWidth(Component component, int width) {
    Dimension dim = component.getPreferredSize();
    component.setPreferredSize(new Dimension(width, dim.height));
}

From source file:Main.java

public static void initComponentHeight(final Component... components) {
    if (components == null) {
        return;/* w w  w  . j  a v a  2s . c  o m*/
    }
    for (final Component component : components) {
        if ((component instanceof JComboBox) || (component instanceof JButton)) {
            component.setPreferredSize(new Dimension(component.getPreferredSize().width, 22));
        } else if (component instanceof JTextField) {
            final String lf = UIManager.getLookAndFeel().getClass().getName();
            int i = 22;
            if (lf.equals(LAF_METAL)) {
                i = 23;
            }
            component.setPreferredSize(new Dimension(component.getPreferredSize().width, i));
        }
    }
}

From source file:Main.java

private static void doSetSizeInEDT(final Component component, final int width, final int height) {
    component.setMaximumSize(new Dimension(width, height));
    component.setMinimumSize(new Dimension(width, height));
    component.setPreferredSize(new Dimension(width, height));
    component.setSize(new Dimension(width, height));
}

From source file:Main.java

public static void padPreferredWidthDeep(Component component, int padding) {
    if (component instanceof Container) {
        for (Component child : ((Container) component).getComponents()) {
            padPreferredWidthDeep(child, padding);
        }//w w  w .j av a  2 s . c  om
    }
    component.setPreferredSize(new Dimension((int) component.getPreferredSize().getWidth() + padding,
            (int) component.getPreferredSize().getHeight()));
}