Example usage for javax.swing JComponent setMaximumSize

List of usage examples for javax.swing JComponent setMaximumSize

Introduction

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

Prototype

@BeanProperty(description = "The maximum size of the component.")
public void setMaximumSize(Dimension maximumSize) 

Source Link

Document

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

Usage

From source file:Main.java

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

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   www . j a va2s . com
}

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.ja  v a 2s  . c o m
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//from w w w .j  av a2 s. 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:BoxSample.java

private static void changeBoth(JComponent comp) {
    comp.setAlignmentX(Component.CENTER_ALIGNMENT);
    comp.setAlignmentY(Component.CENTER_ALIGNMENT);
    Dimension dim = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
    comp.setMaximumSize(dim);
}

From source file:BoxSample.java

private static void changeWidth(JComponent comp) {
    comp.setAlignmentX(Component.CENTER_ALIGNMENT);
    comp.setAlignmentY(Component.CENTER_ALIGNMENT);
    Dimension dim = comp.getPreferredSize();
    dim.width = Integer.MAX_VALUE;
    comp.setMaximumSize(dim);
}

From source file:BoxSample.java

private static void changeHeight(JComponent comp) {
    comp.setAlignmentX(Component.CENTER_ALIGNMENT);
    comp.setAlignmentY(Component.CENTER_ALIGNMENT);
    Dimension dim = comp.getPreferredSize();
    dim.height = Integer.MAX_VALUE;
    comp.setMaximumSize(dim);
}

From source file:org.peerfact.impl.service.aggregation.skyeye.visualization.MetricsPlot.java

private static void setSizeOfComponent(JComponent component, Dimension dim) {
    component.setMinimumSize(dim);/*  ww w  .ja  va  2  s  .c o  m*/
    component.setMaximumSize(dim);
    component.setPreferredSize(dim);
    component.setSize(dim);
}

From source file:com.atlassian.theplugin.idea.bamboo.tree.BuildTreeNode.java

private static void setFixedComponentSize(JComponent c, int width, int height) {
    c.setPreferredSize(new Dimension(width, height));
    c.setMinimumSize(new Dimension(width, height));
    c.setMaximumSize(new Dimension(width, height));
}

From source file:Main.java

private Component createStrut() {
    JComponent component = (JComponent) Box.createHorizontalStrut(5);
    component.setMinimumSize(new Dimension(0, 0));
    component.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    return component;
}