Example usage for javax.swing JComponent setAlignmentY

List of usage examples for javax.swing JComponent setAlignmentY

Introduction

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

Prototype

@BeanProperty(description = "The preferred vertical alignment of the component.")
public void setAlignmentY(float alignmentY) 

Source Link

Document

Sets the vertical alignment.

Usage

From source file:Main.java

/** Set the vertical alignment of the given components.  Intended to reduce clutter in GUI code. */
public static void setAlignmentY(float a, JComponent... components) {
    for (JComponent c : components) {
        c.setAlignmentY(a);
    }/*from   ww w  . j a  va 2 s.  c  om*/
}

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 ww w.j  a  va2 s  . c o  m*/
}

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);//  w  w  w .  j  a v a2s .  c om
}

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   ww  w.j  a  va 2  s.co  m
}

From source file:BoxAlignmentDemo.java

protected JPanel createYAlignmentExample(boolean doItRight) {
    JPanel pane = new JPanel();
    String title;//from w w w .ja va2s.  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;
}