Example usage for javax.swing JLabel setAlignmentX

List of usage examples for javax.swing JLabel setAlignmentX

Introduction

In this page you can find the example usage for javax.swing JLabel 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 JLabel toSwingImage(final BufferedImage image) {
    JLabel label = new JLabel(new ImageIcon(image));
    label.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    return label;
}

From source file:Main.java

private static JPanel createLogin() {
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    JLabel label = new JLabel("login panel.");
    label.setFont(label.getFont().deriveFont(Font.ITALIC, 24f));
    label.setAlignmentX(0.5f);
    label.setBorder(new EmptyBorder(0, 20, 0, 20));
    p.add(Box.createVerticalStrut(36));
    p.add(label);/*from   www  . j a v  a2  s  . co m*/
    p.add(Box.createVerticalStrut(144));
    return p;
}

From source file:BoxLayoutDemo.java

private static JComponent createComponent(String s) {
    JLabel l = new JLabel(s);
    l.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.DARK_GRAY));
    l.setHorizontalAlignment(JLabel.CENTER);
    l.setAlignmentX(Component.CENTER_ALIGNMENT); //use middle of row
    return l;// w  w  w  . j av a2s . c  om
}

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

/**
 * @param message//from  w ww .ja va  2s  .c  o m
 * @return JLabel
 */
public static JLabel newLabelForBox(String message) {
    JLabel label = new JLabel(message);
    label.setMaximumSize(new Dimension(Short.MAX_VALUE, label.getFont().getSize() + 10));
    label.setAlignmentX(Container.CENTER_ALIGNMENT);
    return label;
}

From source file:Main.java

public Main() {
    Box box = new Box(BoxLayout.Y_AXIS);
    add(box);/*from www  .  jav a  2  s .  c o m*/

    JLabel label = new JLabel("I'm centered");
    label.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    box.add(Box.createVerticalGlue());
    box.add(label);
    box.add(Box.createVerticalGlue());
}

From source file:Main.java

public PopupMenu() {
    super(BoxLayout.Y_AXIS);
    final JPopupMenu menu = new JPopupMenu("Options");
    for (int i = 1; i < 20; i++)
        menu.add(new JMenuItem("Option" + i));

    JLabel clickMe = new JLabel("ClickMe");
    clickMe.setAlignmentX(RIGHT_ALIGNMENT);
    clickMe.addMouseListener(new MouseAdapter() {
        @Override/*from   w w w .j  a  v a  2 s.c  o m*/
        public void mouseClicked(MouseEvent e) {
            menu.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    add(clickMe);
}

From source file:AboutDialog.java

public AboutDialog() {
    setTitle("About");
    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    add(Box.createRigidArea(new Dimension(0, 10)));

    JLabel name = new JLabel("Notes");
    name.setAlignmentX(0.5f);
    add(name);/*  w w w.  j a va 2  s .c o m*/

    add(Box.createRigidArea(new Dimension(0, 100)));

    JButton close = new JButton("Close");
    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dispose();
        }
    });

    close.setAlignmentX(0.5f);
    add(close);
    setModalityType(ModalityType.APPLICATION_MODAL);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setSize(300, 200);
}

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);/* w  w w .jav a2s  . co  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;
}

From source file:dnd.ChooseDropActionDemo.java

public ChooseDropActionDemo() {
    super("ChooseDropActionDemo");

    for (int i = 15; i >= 0; i--) {
        from.add(0, "Source item " + i);
    }/*  ww  w .  jav  a2  s  .  c om*/

    for (int i = 2; i >= 0; i--) {
        copy.add(0, "Target item " + i);
        move.add(0, "Target item " + i);
    }

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    dragFrom = new JList(from);
    dragFrom.setTransferHandler(new FromTransferHandler());
    dragFrom.setPrototypeCellValue("List Item WWWWWW");
    dragFrom.setDragEnabled(true);
    dragFrom.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JLabel label = new JLabel("Drag from here:");
    label.setAlignmentX(0f);
    p.add(label);
    JScrollPane sp = new JScrollPane(dragFrom);
    sp.setAlignmentX(0f);
    p.add(sp);
    add(p, BorderLayout.WEST);

    JList moveTo = new JList(move);
    moveTo.setTransferHandler(new ToTransferHandler(TransferHandler.COPY));
    moveTo.setDropMode(DropMode.INSERT);
    JList copyTo = new JList(copy);
    copyTo.setTransferHandler(new ToTransferHandler(TransferHandler.MOVE));
    copyTo.setDropMode(DropMode.INSERT);

    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    label = new JLabel("Drop to COPY to here:");
    label.setAlignmentX(0f);
    p.add(label);
    sp = new JScrollPane(moveTo);
    sp.setAlignmentX(0f);
    p.add(sp);
    label = new JLabel("Drop to MOVE to here:");
    label.setAlignmentX(0f);
    p.add(label);
    sp = new JScrollPane(copyTo);
    sp.setAlignmentX(0f);
    p.add(sp);
    p.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
    add(p, BorderLayout.CENTER);

    ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

    getContentPane().setPreferredSize(new Dimension(320, 315));
}

From source file:ChooseDropActionDemo.java

public ChooseDropActionDemo() {
    super("ChooseDropActionDemo");

    for (int i = 15; i >= 0; i--) {
        from.add(0, "Source item " + i);
    }// ww w.  j ava 2 s. c  o  m

    for (int i = 2; i >= 0; i--) {
        copy.add(0, "Target item " + i);
        move.add(0, "Target item " + i);
    }

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    dragFrom = new JList(from);
    dragFrom.setTransferHandler(new FromTransferHandler());
    dragFrom.setPrototypeCellValue("List Item WWWWWW");
    dragFrom.setDragEnabled(true);
    dragFrom.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JLabel label = new JLabel("Drag from here:");
    label.setAlignmentX(0f);
    p.add(label);
    JScrollPane sp = new JScrollPane(dragFrom);
    sp.setAlignmentX(0f);
    p.add(sp);
    add(p, BorderLayout.WEST);

    JList moveTo = new JList(move);
    moveTo.setTransferHandler(new ToTransferHandler(TransferHandler.COPY));
    moveTo.setDropMode(DropMode.INSERT);
    JList copyTo = new JList(copy);
    copyTo.setTransferHandler(new ToTransferHandler(TransferHandler.MOVE));
    copyTo.setDropMode(DropMode.INSERT);

    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    label = new JLabel("Drop to COPY to here:");
    ;
    label.setAlignmentX(0f);
    p.add(label);
    sp = new JScrollPane(moveTo);
    sp.setAlignmentX(0f);
    p.add(sp);
    label = new JLabel("Drop to MOVE to here:");
    label.setAlignmentX(0f);
    p.add(label);
    sp = new JScrollPane(copyTo);
    sp.setAlignmentX(0f);
    p.add(sp);
    p.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
    add(p, BorderLayout.CENTER);

    ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

    getContentPane().setPreferredSize(new Dimension(320, 315));
}