Example usage for javax.swing JLabel setHorizontalAlignment

List of usage examples for javax.swing JLabel setHorizontalAlignment

Introduction

In this page you can find the example usage for javax.swing JLabel setHorizontalAlignment.

Prototype

@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER",
        "SwingConstants.RIGHT", "SwingConstants.LEADING",
        "SwingConstants.TRAILING" }, description = "The alignment of the label's content along the X axis.")
public void setHorizontalAlignment(int alignment) 

Source Link

Document

Sets the alignment of the label's contents along the X axis.

Usage

From source file:com.thoughtworks.go.agent.bootstrapper.osx.MacAboutBox.java

private JLabel label(String content, Font font) {
    JLabel jLabel = new JLabel(content);
    jLabel.setHorizontalAlignment(JLabel.CENTER);
    if (font != null) {
        jLabel.setFont(font);/*from ww  w . j a  v a  2 s  . c o  m*/
    }
    return jLabel;
}

From source file:com.moneydance.modules.features.importlist.table.HeaderRenderer.java

@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected,
        final boolean hasFocus, final int row, final int column) {
    Component component = this.defaultHeaderTableCellRenderer.getTableCellRendererComponent(table, value,
            hasFocus, hasFocus, row, column);
    if (component instanceof JComponent) {
        JComponent jComponent = (JComponent) component;
        jComponent.setBorder(new EmptyBorder(1, 1, 1, 1));
        jComponent.setOpaque(false);/*w ww  . ja  v  a  2 s. c o  m*/

        if (jComponent instanceof JLabel) {
            JLabel jLabel = (JLabel) jComponent;
            jLabel.setHorizontalAlignment(SwingConstants.LEFT);
        }
    }

    component.setFont(Preferences.getHeaderFont());
    component.setForeground(Preferences.getHeaderForeground());

    component.setSize(
            new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight()));
    component.setMinimumSize(
            new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight()));
    component.setPreferredSize(
            new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight()));
    component.setMaximumSize(
            new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight()));

    return component;
}

From source file:com.opendoorlogistics.studio.tables.grid.HeaderCellRenderer.java

/**
 * //from  ww  w  .j a va  2 s  .c  o m
 */
protected void initLabel(JLabel label) {
    label.setOpaque(true);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
}

From source file:LayeredPaneDemo.java

private JLabel createColoredLabel(String text, Color color, Point origin) {
    JLabel label = new JLabel(text);
    label.setVerticalAlignment(JLabel.TOP);
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setOpaque(true);//from   w w w  . jav  a 2 s. c o  m
    label.setBackground(color);
    label.setForeground(Color.black);
    label.setBorder(BorderFactory.createLineBorder(Color.black));
    label.setBounds(origin.x, origin.y, 140, 140);
    return label;
}

From source file:org.apache.commons.httpclient.contrib.proxy.PluginProxyTestApplet.java

private JLabel getLabel(String text) {
    JLabel result = new JLabel(text);
    result.setHorizontalAlignment(JLabel.CENTER);
    return result;
}

From source file:components.LayeredPaneDemo2.java

private JLabel createColoredLabel(String text, Color color) {
    JLabel label = new JLabel(text);
    label.setVerticalAlignment(JLabel.TOP);
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setOpaque(true);/* w ww  .  j  ava2s.  com*/
    label.setBackground(color);
    label.setForeground(Color.black);
    label.setBorder(BorderFactory.createLineBorder(Color.black));
    label.setPreferredSize(new Dimension(140, 140));
    return label;
}

From source file:org.jdal.swing.table.AnnotationFormatTableCellRenderer.java

/**
 * {@inheritDoc}/*w ww. j a v  a 2s  . com*/
 */
@SuppressWarnings("unchecked")
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {

    Class<?> clazz = table.getColumnClass(column);
    if (Number.class.isAssignableFrom(clazz)) {
        TableModel tableModel = table.getModel();
        if (tableModel instanceof ListTableModel) {
            ListTableModel listTableModel = (ListTableModel) tableModel;
            Class<?> modelClass = ((ListTableModel) tableModel).getModelClass();
            String propertyName = listTableModel.getPropertyName(column);
            Printer<Object> printer = (Printer<Object>) FormatUtils.getPrinter(modelClass, propertyName);
            if (printer != null) {
                value = printer.print(value, Locale.getDefault());
                JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
                        row, column);
                label.setHorizontalAlignment(JLabel.RIGHT);
                return label;
            }
        }
    }
    TableCellRenderer renderer = table.getDefaultRenderer(clazz);

    return renderer != null
            ? renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column)
            : null;
}

From source file:org.apache.commons.httpclient.contrib.proxy.PluginProxyTestApplet.java

private JLabel getHeaderLabel(String text) {
    JLabel result = new JLabel("<html><u><b>" + text + "</b></u></html>");
    result.setHorizontalAlignment(JLabel.CENTER);
    return result;
}

From source file:kuvalataaja.user_interface.GUI.java

/** 
 * Creates a label to keep the rest of the code cleaner.
 * @return The created label // ww  w .j a v a2s. com
 */
private JLabel createJLabel() {
    JLabel label = new JLabel();
    label.setText("<html><p>Hello and welcome to my program!</p></html>");
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setVerticalAlignment(JLabel.CENTER);
    return label;
}

From source file:com.orthancserver.OrthancConfigurationDialog.java

public OrthancConfigurationDialog() {
    final JPanel contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(20, 5, 5, 5));
    contentPanel.setLayout(new GridLayout2(0, 2, 20, 5));

    JLabel label = new JLabel("Name:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);//from  ww  w.  jav  a2s  . c om
    contentPanel.add(name_);

    label = new JLabel("URL:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);
    contentPanel.add(url_);

    label = new JLabel("Username:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);
    contentPanel.add(username_);

    label = new JLabel("Password:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);
    contentPanel.add(password_);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(contentPanel, BorderLayout.NORTH);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    getContentPane().add(buttonPane, BorderLayout.SOUTH);
    {
        {
            JButton test = new JButton("Test connection");
            test.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    OrthancConnection orthanc = CreateConnection();
                    try {
                        JSONObject system = (JSONObject) orthanc.ReadJson("system");
                        JOptionPane.showMessageDialog(null,
                                "Successfully connected to this Orthanc server " + "(version: "
                                        + (String) system.get("Version") + ")!",
                                "Success", JOptionPane.INFORMATION_MESSAGE);
                    } catch (IOException e) {
                        JOptionPane.showMessageDialog(null, "Cannot connect to this Orthanc server!", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    }
                }
            });
            buttonPane.add(test);
        }
        {
            JButton okButton = new JButton("Add");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    isSuccess_ = true;
                    setVisible(false);
                }
            });
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    setVisible(false);
                }
            });
            buttonPane.add(cancelButton);
        }
    }

    setUndecorated(false);
    setSize(500, 500);
    setTitle("Add new server");
    setModal(true);
}