Example usage for javax.swing JComponent setMinimumSize

List of usage examples for javax.swing JComponent setMinimumSize

Introduction

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

Prototype

@BeanProperty(description = "The minimum size of the component.")
public void setMinimumSize(Dimension minimumSize) 

Source Link

Document

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

Usage

From source file:BoxAlignmentDemo.java

protected JPanel createLabelAndComponent(boolean doItRight) {
    JPanel pane = new JPanel();

    JComponent component = new JPanel();
    Dimension size = new Dimension(150, 100);
    component.setMaximumSize(size);/*  ww  w . ja  v a 2  s .c  o  m*/
    component.setPreferredSize(size);
    component.setMinimumSize(size);
    TitledBorder border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER,
            TitledBorder.BELOW_TOP);
    border.setTitleColor(Color.black);
    component.setBorder(border);

    JLabel label = new JLabel("This is a JLabel");
    String title;
    if (doItRight) {
        title = "Matched";
        label.setAlignmentX(CENTER_ALIGNMENT);
    } else {
        title = "Mismatched";
    }

    pane.setBorder(BorderFactory.createTitledBorder(title));
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    pane.add(label);
    pane.add(component);
    return pane;
}

From source file:BoxAlignmentDemo.java

protected JPanel createYAlignmentExample(boolean doItRight) {
    JPanel pane = new JPanel();
    String title;/*w  w w. ja v a 2s  .c om*/

    JComponent component1 = new JPanel();
    Dimension size = new Dimension(100, 50);
    component1.setMaximumSize(size);
    component1.setPreferredSize(size);
    component1.setMinimumSize(size);
    TitledBorder border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER,
            TitledBorder.BELOW_TOP);
    border.setTitleColor(Color.black);
    component1.setBorder(border);

    JComponent component2 = new JPanel();
    size = new Dimension(100, 50);
    component2.setMaximumSize(size);
    component2.setPreferredSize(size);
    component2.setMinimumSize(size);
    border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER,
            TitledBorder.BELOW_TOP);
    border.setTitleColor(Color.black);
    component2.setBorder(border);

    if (doItRight) {
        title = "Matched";
    } else {
        component1.setAlignmentY(TOP_ALIGNMENT);
        title = "Mismatched";
    }

    pane.setBorder(BorderFactory.createTitledBorder(title));
    pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
    pane.add(component1);
    pane.add(component2);
    return pane;
}

From source file:de.tud.kom.p2psim.impl.skynet.visualization.MetricsPlot.java

private void setSizeOfComponent(JComponent component, Dimension dim) {
    component.setMinimumSize(dim);
    component.setMaximumSize(dim);//ww  w .ja  v  a  2 s  .  c  om
    component.setPreferredSize(dim);
    component.setSize(dim);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopSplitPanel.java

@Override
public void add(Component component) {
    JComponent jComponent = DesktopComponentsHelper.getComposition(component);
    jComponent.setMinimumSize(new Dimension());
    if (ownComponents.isEmpty()) {
        impl.setLeftComponent(jComponent);
    } else {//from   ww  w .  j ava  2  s.c o m
        impl.setRightComponent(jComponent);
    }

    if (component.getId() != null) {
        componentByIds.put(component.getId(), component);
    }

    if (frame != null) {
        if (component instanceof BelongToFrame && ((BelongToFrame) component).getFrame() == null) {
            ((BelongToFrame) component).setFrame(frame);
        } else {
            frame.registerComponent(component);
        }
    }

    if (component instanceof DesktopAbstractComponent && !isEnabledWithParent()) {
        ((DesktopAbstractComponent) component).setParentEnabled(false);
    }

    ownComponents.add(component);
}

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

private void computePreferredSizes() {
    for (String key : sizeGroups.keySet()) {
        int width = -1;
        int height = -1;
        for (JComponent component : sizeGroups.get(key)) {
            if (width < component.getPreferredSize().width) {
                width = component.getPreferredSize().width;
            }/*from www.  ja  va  2 s  . co m*/
            if (height < component.getPreferredSize().height) {
                height = component.getPreferredSize().height;
            }
        }

        // Sometimes the preferred width of a component can be too small to accommodate the contained text and in
        // that case the text is truncated and ellipsis will be shown. To fix it the width is increased.
        width += 2;

        for (JComponent component : sizeGroups.get(key)) {
            component.setMinimumSize(new Dimension(width, height));
            component.setMaximumSize(new Dimension(width, height));
            component.setPreferredSize(new Dimension(width, height));
        }
    }
    sizeGroups.clear();
}

From source file:openlr.mapviewer.coding.ui.AbstractCodingOptionsDialog.java

/**
 * Creates a new instance. Sets up the entire dialog.
 * /*from   ww  w. j a  v a 2  s .c  om*/
 * @param type
 *            The type of coding this dialog instance is dealing with
 * @param propsHolder
 *            The encoding and decoding properties holder
 * @param fcf
 *            The file choose factory to use
 * @param title
 *            The dialog title
 */
public AbstractCodingOptionsDialog(final CodingType type, final CodingPropertiesHolder propsHolder,
        final FileChooserFactory fcf, final String title) {

    codingType = type;
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setTitle(title);
    setResizable(false);

    JPanel contentPane = new JPanel(new MigLayout("insets 0", "[grow]", "[][bottom]"));

    setContentPane(contentPane);

    JButton applyBtn = new JButton("Apply");
    applyBtn.setToolTipText("Stores the current settings for the current MapViewer run");

    ApplyChangesListener applyListener = new ApplyChangesListener(type, propsHolder, optionsTextFields);
    applyBtn.addActionListener(applyListener);

    defaultConfig = loadDefaultSettings();

    JButton resetBtn = new JButton("Reset");
    resetBtn.setToolTipText("Resets the properties to the defaults");
    resetBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {

            setValues(defaultConfig);
        }
    });

    JButton closeBtn = new JButton("Close");
    closeBtn.setToolTipText("Closes the dialog. The last applied settings are kept.");

    closeBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            AbstractCodingOptionsDialog.this.dispose();
        }
    });

    setJMenuBar(new CodingDialogMenuBar(this, propsHolder, fcf, applyListener));

    JComponent form = buildForm(propsHolder.getProperties(codingType));

    form.setMaximumSize(FORM_PANEL_MAXIMUM_SIZE);
    form.setMinimumSize(FORM_PANEL_MINIMUM_SIZE);

    add(form, "span,grow,wrap");
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(applyBtn);
    buttonPanel.add(resetBtn);

    add(buttonPanel);
    setIconImage(MapViewerGui.OPENLR_ICON);

    setLocationRelativeTo(null);

    pack();
}

From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java

public static void setWidths(JComponent component, int width) {
    Dimension dim = component.getPreferredSize();
    dim.width = width;/*w w w  . j  av  a  2s. c  o  m*/
    component.setPreferredSize(dim);
    component.setMaximumSize(dim);
    component.setMinimumSize(dim);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** 
 * Lays out the components composing main panel. 
 * /*w  ww.ja  va2 s . c om*/
 * @param fromPreferences   Pass <code>true</code> to indicate that the 
 *                      method is invoked while setting the user 
 *                      preferences, <code>false</code> otherwise.
 */
private void layoutComponents(boolean fromPreferences) {
    //initSplitPanes();
    Dimension d;
    int diff;
    Container container = getContentPane();
    container.removeHierarchyBoundsListener(boundsAdapter);
    int width = 0, height = 0;
    JComponent rightComponent;
    //int divider = 0;
    int vExtra = 2;
    int addition;
    switch (displayMode) {
    case RENDERER:
        rightComponent = model.getMetadataViewer().getEditorUI();
        rendererSplit.setRightComponent(rightComponent);
        if (restoreSize == null) {
            rendererSplit.setResizeWeight(1.0);
            return;
        }
        d = model.getMetadataViewer().getIdealRendererSize();
        rightComponent.setMinimumSize(d);
        tabs.setMinimumSize(restoreSize);
        height = restoreSize.height;
        diff = d.height - restoreSize.height;
        if (diff > 0)
            height += diff;
        else
            height += vExtra;
        addition = rendererSplit.getDividerSize() + 2 * (refInsets.left + refInsets.right);

        width = restoreSize.width + d.width;
        width += 4 * addition;
        break;
    case HISTORY:
        container.remove(mainComponent);
        historyUI.doGridLayout();
        addComponents(historySplit, tabs, historyUI);
        mainComponent = historySplit;
        container.add(mainComponent, BorderLayout.CENTER);
        container.validate();
        container.repaint();
        height = restoreSize.height;
        width = restoreSize.width;
        d = historyUI.getIdealSize();
        addition = historySplit.getDividerSize() + 2 * (refInsets.top + refInsets.bottom);
        height += d.height;
        historySplit.setResizeWeight(0.49);
        height += addition;
        break;
    case HISTORY_AND_RENDERER:
        historySplit.setResizeWeight(0.49);
        container.remove(mainComponent);
        historyUI.doGridLayout();
        rightComponent = model.getMetadataViewer().getEditorUI();
        addComponents(rendererSplit, tabs, rightComponent);
        addComponents(historySplit, rendererSplit, historyUI);
        mainComponent = historySplit;
        container.add(mainComponent, BorderLayout.CENTER);
        container.validate();
        container.repaint();

        d = model.getMetadataViewer().getIdealRendererSize();
        height = restoreSize.height;
        diff = d.height - restoreSize.height;
        if (diff > 0)
            height += diff;
        else
            height += vExtra;
        addition = rendererSplit.getDividerSize() + 2 * (refInsets.left + refInsets.right);

        width = restoreSize.width + d.width;
        width += 4 * addition;
        d = historyUI.getPreferredSize();
        addition = historySplit.getDividerSize() + 2 * (refInsets.top + refInsets.bottom);
        height += d.height;
        height += addition;
        break;
    case NEUTRAL:
        rightComponent = model.getMetadataViewer().getEditorUI();
        rendererSplit.remove(rightComponent);
        if (restoreSize == null)
            return;
        width = restoreSize.width;
        height = restoreSize.height;
        break;
    default:
    }
    //rendererSplit.setDividerLocation(-1);
    //rendererSplit.setResizeWeight(1.0);
    //historySplit.setDividerLocation(-1);
    d = getIdealSize(width, height);

    /* Need to review that code.
     * Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int w = (int) (screen.width*SCREEN_RATIO);
    int h = (int) (screen.height*SCREEN_RATIO);
    if (d.width > w || d.height > h) {
       setSize(width, height);
    } else setSize(d);
    */
    setSize(d);
    setPreferredSize(d);
    pack();
    container.addHierarchyBoundsListener(boundsAdapter);
}