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:org.peerfact.impl.service.aggregation.skyeye.visualization.MetricsPlot.java

private static void setSizeOfComponent(JComponent component, Dimension dim) {
    component.setMinimumSize(dim);/*from ww w . j ava 2s  . co 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:de.ailis.xadrian.utils.SwingUtils.java

/**
 * Sets the preferred width of the specified component.
 * /*from ww w  . j a  v  a 2  s.  co m*/
 * @param component
 *            The component
 * @param width
 *            The preferred width
 */
public static void setPreferredWidth(final JComponent component, final int width) {
    component.setPreferredSize(new Dimension(width, component.getPreferredSize().height));
}

From source file:de.ailis.xadrian.utils.SwingUtils.java

/**
 * Sets the preferred height of the specified component.
 * //from w w w.j  ava2  s  . c  o m
 * @param component
 *            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 Main() {
    super(new GridLayout(1, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images/middle.gif");

    JComponent panel1 = makeTextPanel("Panel #1");
    tabbedPane.addTab("Tab 1", icon, panel1, "Does nothing");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    JComponent panel2 = makeTextPanel("Panel #2");
    tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    JComponent panel3 = makeTextPanel("Panel #3");
    tabbedPane.addTab("Tab 3", icon, panel3, "Still does nothing");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    JComponent panel4 = makeTextPanel("Panel #4 (has a preferred size of 410 x 50).");
    panel4.setPreferredSize(new Dimension(410, 50));
    tabbedPane.addTab("Tab 4", icon, panel4, "Does nothing at all");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    add(tabbedPane);//w  w w . ja  va2 s  . co  m

    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}

From source file:components.TabbedPaneDemo.java

public TabbedPaneDemo() {
    super(new GridLayout(1, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images/middle.gif");

    JComponent panel1 = makeTextPanel("Panel #1");
    tabbedPane.addTab("Tab 1", icon, panel1, "Does nothing");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    JComponent panel2 = makeTextPanel("Panel #2");
    tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    JComponent panel3 = makeTextPanel("Panel #3");
    tabbedPane.addTab("Tab 3", icon, panel3, "Still does nothing");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    JComponent panel4 = makeTextPanel("Panel #4 (has a preferred size of 410 x 50).");
    panel4.setPreferredSize(new Dimension(410, 50));
    tabbedPane.addTab("Tab 4", icon, panel4, "Does nothing at all");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    //Add the tabbed pane to this panel.
    add(tabbedPane);/*w  w  w.jav  a 2s .  c  o  m*/

    //The following line enables to use scrolling tabs.
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}

From source file:TabbedPaneDemo.java

public TabbedPaneDemo() {
    super(new GridLayout(1, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images/middle.gif");

    JComponent panel1 = makeTextPanel("Panel #1");
    tabbedPane.addTab("Tab 1", icon, panel1, "Does nothing");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    JComponent panel2 = makeTextPanel("Panel #2");
    tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    JComponent panel3 = makeTextPanel("Panel #3");
    tabbedPane.addTab("Tab 3", icon, panel3, "Still does nothing");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    JComponent panel4 = makeTextPanel("Panel #4 (has a preferred size of 410 x 50).");
    panel4.setPreferredSize(new Dimension(410, 50));
    tabbedPane.addTab("Tab 4", icon, panel4, "Does nothing at all");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);

    //Add the tabbed pane to this panel.
    add(tabbedPane);/*from  w  w w  .j  a v  a2s  .c om*/

    //Uncomment the following line to use scrolling tabs.
    //tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}

From source file:lu.lippmann.cdb.common.gui.MultiPanel.java

/**
 * Constructor.// w w  w .  j a va2  s . co  m
 */
public MultiPanel(final ListOrderedMap<JComponent, Integer> mapPanels, final int w, final int h,
        final boolean withWeight) {

    final int total = mapPanels.keySet().size();

    if (!withWeight)
        setLayout(new GridLayout(0, 1));

    final int w2 = w - 10 * total;
    final int h2 = h - 75;

    final Map<JComponent, Color> choosedColor = new HashMap<JComponent, Color>();

    int i = 0;
    for (final JComponent p : mapPanels.keySet()) {
        final Dimension size = new Dimension((int) (w2 * (mapPanels.get(p) / 100.0)), h2);
        p.setPreferredSize(size);
        choosedColor.put(p, COLORS[i]);
        p.setBackground(COLORS[i]);
        p.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        add(p);
        i++;
    }

    if (withWeight) {
        /** add percents **/
        for (final JComponent p : mapPanels.keySet()) {
            final int perc = mapPanels.get(p);
            final int percent = (int) (w2 * (mapPanels.get(p) / 100.0));
            final Dimension size = new Dimension(percent, 20);
            final JPanel arrow = new JPanel();
            arrow.setPreferredSize(size);
            final JLabel label = new JLabel(perc + "%");
            label.setForeground(choosedColor.get(p).darker());
            arrow.add(label);
            add(arrow);
        }
    }
}

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);/*from   w  w  w.j  a va2s .  com*/
    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;/*from  ww  w. j av 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;
}