Example usage for javax.swing JButton setAlignmentX

List of usage examples for javax.swing JButton setAlignmentX

Introduction

In this page you can find the example usage for javax.swing JButton setAlignmentX.

Prototype

@BeanProperty(description = "The preferred horizontal alignment of the component.")
public void setAlignmentX(float alignmentX) 

Source Link

Document

Sets the horizontal alignment.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
        public boolean isOptimizedDrawingEnabled() {
            return false;
        }/* w ww.ja  va 2 s  .  com*/
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(25, 25));
    button.setBackground(Color.white);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(50, 50));
    button.setBackground(Color.gray);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100, 100));
    button.setBackground(Color.black);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    frame.add(panel, BorderLayout.CENTER);

    frame.setSize(400, 300);
    frame.setVisible(true);
}

From source file:YAxisAlignX.java

private static Container layoutComponents(String title, float alignment) {
    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);//from ww  w .  java 2  s .  co m

    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(alignment);
        container.add(button);
    }
    return container;
}

From source file:AlignX.java

private static Container makeIt(String labelChar, float alignment) {
    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);// w  w  w .  j  ava2  s .  c  o m

    for (int i = 1; i < 6; i++) {
        String label = makeLabel(labelChar, i * 2);
        JButton button = new JButton(label);
        button.setAlignmentX(alignment);
        container.add(button);
    }
    return container;
}

From source file:YAxisAlignX.java

private static Container makeIt(String title, float alignment) {
    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);//www  .j  a va 2s.co  m

    for (int i = 0, n = labels.length; i < n; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(alignment);
        container.add(button);
    }
    return container;
}

From source file:layout.BoxLayoutDemo.java

private static void addAButton(String text, Container container) {
    JButton button = new JButton(text);
    button.setAlignmentX(Component.CENTER_ALIGNMENT);
    container.add(button);//  w  w w.j a  va2  s  .co m
}

From source file:YAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth() - insets.left - insets.right;
            int halfWidth = width / 2 + insets.left;
            int height = getHeight();
            int halfHeight = height / 2 + insets.top;
            g.drawLine(halfWidth, 0, halfWidth, height);
        }/*from  w w w  .  ja  v  a  2s  . c o m*/
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.LEFT_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentX(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentX(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:Main.java

public static void showMessage(String title, String str) {
    JFrame info = new JFrame(title);
    JTextArea t = new JTextArea(str, 15, 40);
    t.setEditable(false);/*from w  ww .  j  a v a  2  s .c o  m*/
    t.setLineWrap(true);
    t.setWrapStyleWord(true);
    JButton ok = new JButton("Close");
    ok.addActionListener(windowCloserAction);
    info.getContentPane().setLayout(new BoxLayout(info.getContentPane(), BoxLayout.Y_AXIS));
    info.getContentPane().add(new JScrollPane(t));
    info.getContentPane().add(ok);
    ok.setAlignmentX(Component.CENTER_ALIGNMENT);
    info.pack();
    //info.setResizable(false);
    centerFrame(info);
    //info.show();
    info.setVisible(true);
}

From source file:org.jdal.swing.form.FormUtils.java

/**
 * Get Default OK Button from LookAndFeel (like JOptionPane)
 *//*  ww  w. jav a 2 s  . c  om*/
public static JButton newOKButton() {
    String text = StaticMessageSource.getMessage("Accept");
    int mnemonic = getMnemonic("OptionPane.okButtonMnemonic");
    JButton b = new JButton(text, OK_ICON);
    b.setMnemonic(mnemonic);
    b.setAlignmentX(Container.CENTER_ALIGNMENT);
    b.setAlignmentY(Container.CENTER_ALIGNMENT);
    return b;
}

From source file:org.jdal.swing.form.FormUtils.java

/**
 * Get Default Cancel Button from LookAndFeel (like JOptionPane)
 *//*w  w  w  . ja v  a2s.c o  m*/
public static JButton newCancelButton() {
    String text = StaticMessageSource.getMessage("Cancel");
    int mnemonic = getMnemonic("OptionPane.cancelButtonMnemonic");
    JButton b = new JButton(text, CANCEL_ICON);
    b.setMnemonic(mnemonic);
    b.setAlignmentX(Container.CENTER_ALIGNMENT);
    b.setAlignmentY(Container.CENTER_ALIGNMENT);

    return b;
}

From source file:components.ListDialogRunner.java

public static JPanel createUI() {
    //Create the labels.
    JLabel intro = new JLabel("The chosen name:");
    final JLabel name = new JLabel(names[1]);
    intro.setLabelFor(name);/*from   w ww .ja  v a  2s .c  o m*/

    //Use a wacky font if it exists. If not, this falls
    //back to a font we know exists.
    name.setFont(getAFont());

    //Create the button.
    final JButton button = new JButton("Pick a new name...");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String selectedName = ListDialog.showDialog(frame, button, "Baby names ending in O:",
                    "Name Chooser", names, name.getText(), "Cosmo  ");
            name.setText(selectedName);
        }
    });

    //Create the panel we'll return and set up the layout.
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
    intro.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    name.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    button.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    //Add the labels to the content pane.
    panel.add(intro);
    panel.add(Box.createVerticalStrut(5)); //extra space
    panel.add(name);

    //Add a vertical spacer that also guarantees us a minimum width:
    panel.add(Box.createRigidArea(new Dimension(150, 10)));

    //Add the button.
    panel.add(button);

    return panel;
}