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:de.atomfrede.tools.evalutation.ui.ExceptionDialog.java

@Override
public JComponent createContentPanel() {
    // TODO use here nicer layout, maybe with an icon

    JPanel panel = new JPanel(new BorderLayout(10, 10));
    panel.setBorder(BorderFactory.createEmptyBorder(20, 40, 40, 40));

    JLabel label = new JLabel("<html>An error occured!<br/>" + exception.toString() + "</html>");
    label.setHorizontalAlignment(SwingConstants.LEFT);
    panel.add(label, BorderLayout.CENTER);
    panel.add(new JLabel(Icons.IC_DIALOG_ERROR_LARGE), BorderLayout.WEST);
    setSize(panel.getPreferredSize());/*from  ww  w  .j  av  a  2  s.  c om*/
    return panel;
}

From source file:com.game.ui.views.UserDialog.java

public UserDialog(String message, JFrame frame) {
    setLayout(new BorderLayout(5, 5));
    setModalityType(ModalityType.APPLICATION_MODAL);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setResizable(false);// w  w w. j ava2  s  . c o m
    ImageIcon icon = null;
    try {
        icon = GameUtils.shrinkImage("warning.gif", 30, 30);
    } catch (IOException e) {
        System.out.println("Dialog : showDialogForMap(): Exception occured :" + e);
        e.printStackTrace();
    }
    JPanel panel = new JPanel();
    JLabel label = new JLabel(icon);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    label.setText(message);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setHorizontalAlignment(0);
    panel.add(label);
    add(panel, BorderLayout.NORTH);
    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
    txt = new JTextField();
    txt.setPreferredSize(new Dimension(150, 30));
    txt.setAlignmentX(.5f);
    txt.setMaximumSize(new Dimension(150, 30));
    contentPanel.add(txt);
    contentPanel.add(Box.createVerticalStrut(10));
    JButton btn = new JButton("Submit.");
    btn.setAlignmentX(.5f);
    btn.setPreferredSize(new Dimension(50, 25));
    btn.addActionListener(this);
    validationMess = new JLabel("All fields are mandatory");
    validationMess.setVisible(false);
    validationMess.setForeground(Color.red);
    validationMess.setAlignmentX(.5f);
    contentPanel.add(btn);
    contentPanel.add(Box.createVerticalStrut(10));
    contentPanel.add(validationMess);
    contentPanel.add(Box.createVerticalGlue());
    add(contentPanel, BorderLayout.CENTER);
    pack();
    setSize(new Dimension(300, 200));
    setLocationRelativeTo(frame);
    setVisible(true);
}

From source file:org.jfree.chart.demo.RightPanel.java

public RightPanel(int x, int y, int width, int height, String baude[], String name[]) {

    setBackground(new Color(176, 199, 246));

    this.width = width;
    this.height = height;

    Data[0] = "8";
    Data[1] = "9";

    Name = name;/*from w  w  w .  j av a2 s .c  om*/
    Baude = baude;

    setLayout(new GridLayout(8, 1, 0, 0));

    lblName = new JLabel("Name");
    lblName.setHorizontalAlignment(SwingConstants.CENTER);
    lblName.setFont(new Font("Arial", 15, 16));
    add(lblName);

    comboBox = new JComboBox(Name);
    comboBox.setFont(new Font("Arial", 15, 16));
    add(comboBox);

    JLabel lblBaude = new JLabel("Baude");
    lblBaude.setFont(new Font("Arial", 15, 16));
    lblBaude.setHorizontalAlignment(SwingConstants.CENTER);
    add(lblBaude);

    final JComboBox comboBox_1 = new JComboBox(Baude);
    comboBox_1.setFont(new Font("Arial", 15, 16));
    add(comboBox_1);

    JLabel lblDataSize = new JLabel("Data size");
    lblDataSize.setHorizontalAlignment(SwingConstants.CENTER);
    lblDataSize.setFont(new Font("Arial", 15, 16));
    add(lblDataSize);

    final JComboBox comboBox_2 = new JComboBox(Data);
    comboBox_2.setFont(new Font("Arial", 15, 16));
    add(comboBox_2);

    JSeparator separator = new JSeparator();
    add(separator);

    btnOpen = new JButton("Open");
    btnOpen.setFont(new Font("Arial", 15, 16));
    btnOpen.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (btnOpen.getText() == "Open") {
                btnOpen.setText("Close");
                open = true;
                int baude = 9600, data = 8;
                try {
                    baude = Integer.parseInt((String) comboBox_1.getSelectedItem());
                    data = Integer.parseInt((String) comboBox_2.getSelectedItem());
                } catch (Exception e) {
                    errors += "Enter correct Bauderate\n";
                    error_flag = true;

                }
                comport = new Comport((String) comboBox.getSelectedItem(), baude, data);
                comport.start();

            } else {
                comport.flag = false;
                btnOpen.setText("Open");
                open = false;

                comport.close();
                //   comport.stop();

                System.out.println("Comport = " + comport.isAlive());
                System.out.println("Comport life  = " + comport.get_life());

            }
        }
    });
    add(btnOpen);
    setBounds(x + 50, y, width - 40, height - 20);
    err.setBounds(x + 50, y, 50, 50);
    //add(err);

}

From source file:be.tutul.naheulcraft.launcher.auth.LogInForm.java

private void createInterface() {
    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = 2;/*  ww w . ja v a 2s  .  c  o  m*/
    constraints.gridx = 0;
    constraints.gridy = -1;
    constraints.weightx = 1.0D;

    add(Box.createGlue());

    JLabel usernameLabel = new JLabel("Pseudo : ");
    Font labelFont = usernameLabel.getFont().deriveFont(1);
    Font smalltextFont = usernameLabel.getFont().deriveFont(labelFont.getSize() - 2.0F);

    usernameLabel.setFont(labelFont);
    add(usernameLabel, constraints);
    add(this.usernameField, constraints);

    add(Box.createVerticalStrut(10), constraints);

    JLabel passwordLabel = new JLabel("Mot de passe :");
    passwordLabel.setFont(labelFont);
    add(passwordLabel, constraints);
    add(this.passwordField, constraints);

    JLabel forgotPasswordLabel = new JLabel("(oubli ?)");
    forgotPasswordLabel.setCursor(new Cursor(12));
    forgotPasswordLabel.setFont(smalltextFont);
    forgotPasswordLabel.setHorizontalAlignment(4);
    forgotPasswordLabel.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            try {
                Util.openLink(Variables.lost);
            } catch (Exception e1) {
                LogInForm.this.login.getLauncher().getLogger()
                        .error("Impossible d'ouvrir le lien pour les logins oublis");
                JOptionPane.showMessageDialog(LogInForm.this.login.getLauncher().getPanel(),
                        "Impossible d'ouvrir la page\nRendez-vous sur le site de NaheulCraft pour rcuprer vos identifiants",
                        "Impossible d'ouvrir l'URL", 0);
            }
        }
    });
    add(forgotPasswordLabel, constraints);

    createUserDropdownPanel(labelFont);
    add(this.userDropdownPanel, constraints);

    add(Box.createVerticalStrut(10), constraints);
}

From source file:com.od.jtimeseries.ui.visualizer.chart.TimeSeriesChart.java

private void createNoChartsPanel() {
    noChartsPanel.setLayout(new BorderLayout());
    JLabel noSeriesLabel = new JLabel("No Timeseries Selected");
    noSeriesLabel.setHorizontalAlignment(JLabel.CENTER);
    noSeriesLabel.setVerticalAlignment(JLabel.CENTER);
    noChartsPanel.add(noSeriesLabel);//from  w  w  w  .  j av a2s. c om
}

From source file:com.openbravo.pos.util.ThumbNailBuilder.java

public Image getThumbNailText(Image img, String text) {
    /*//from   w  w  w.  ja v  a 2 s .c  o m
     * Create an image containing a thumbnail of the product image,
     * or default image.
     * 
     * Then apply the text of the product name. Use text wrapping.
     * 
     * If the product name is too big for the label, ensure that
     * the first part is displayed.
     */

    img = getThumbNail(img);

    BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = imgtext.createGraphics();

    // The text
    // <p style="width: 100px"> DOES NOT WORK PROPERLY.
    // use width= instead.
    String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">"
            + StringEscapeUtils.escapeHtml(text) + "</p>";

    JLabel label = new JLabel(html);
    label.setOpaque(false);
    //label.setText("<html><center>Line1<br>Line2");
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setVerticalAlignment(javax.swing.SwingConstants.TOP);
    Dimension d = label.getPreferredSize();
    label.setBounds(0, 0, imgtext.getWidth(), d.height);

    // The background
    Color c1 = new Color(0xff, 0xff, 0xff, 0x40);
    Color c2 = new Color(0xff, 0xff, 0xff, 0xd0);

    //        Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight());
    //        float radius = imgtext.getWidth() / 3;
    //        float[] dist = {0.1f, 1.0f};
    //        Color[] colors = {c2, c1};        
    //        Paint gpaint = new RadialGradientPaint(center, radius, dist, colors);
    Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true);

    g2d.drawImage(img, 0, 0, null);
    int ypos = imgtext.getHeight() - label.getHeight();
    int ypos_min = -4; // todo: configurable
    if (ypos < ypos_min)
        ypos = ypos_min; // Clamp label
    g2d.translate(0, ypos);
    g2d.setPaint(gpaint);
    g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight());
    label.paint(g2d);

    g2d.dispose();

    return imgtext;
}

From source file:com.googlecode.commons.swing.component.datetime.MiniDateCalendar.java

private void init() {
    final DateFormatSymbols dfs = new DateFormatSymbols(locale);
    CollectionUtils.addAll(this.weekdays, dfs.getShortWeekdays());

    for (int i = 0; i < 7; i++) {
        orderedWeekdays.add(((i + weekDayStart - 1) % 7) + 1);
    }/*from  w w w . j a va2  s. c  o m*/

    setLayout(new BorderLayout());
    SizeUtils.setAllWidths(this, 150);
    SizeUtils.setAllHeights(this, 180);

    panNorth = new JPanel(new BorderLayout());
    add(panNorth, BorderLayout.NORTH);

    btnPrev = new JButton();
    SizeUtils.setAllWidths(btnPrev, 18);
    SizeUtils.setAllHeights(btnPrev, 18);
    btnPrev.setIcon(DefaultIcons.resultset_previous());
    btnPrev.setMargin(new Insets(0, 0, 0, 0));
    btnPrev.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onClickPrev();
        }
    });
    panNorth.add(btnPrev, BorderLayout.WEST);

    lblMonth = new JLabel();
    SizeUtils.setMinHeight(lblMonth, 0);
    SizeUtils.setPreferredHeight(lblMonth, 0);
    lblMonth.setHorizontalAlignment(SwingConstants.CENTER);
    panNorth.add(lblMonth, BorderLayout.CENTER);

    btnNext = new JButton();
    btnNext.setIcon(DefaultIcons.resultset_next());
    SizeUtils.setAllWidths(btnNext, 18);
    SizeUtils.setAllHeights(btnNext, 18);
    btnNext.setMargin(new Insets(0, 0, 0, 0));
    btnNext.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onClickNext();
        }
    });
    panNorth.add(btnNext, BorderLayout.EAST);

    panCenter = new JPanel();
    panCenter.setLayout(new GridLayout(7, 7));
    add(panCenter, BorderLayout.CENTER);

    for (int col = 0; col < 7; col++) {
        JLabel lblDay = new JLabel(weekdays.get(orderedWeekdays.get(col)));
        lblDay.setHorizontalAlignment(SwingConstants.CENTER);
        panCenter.add(lblDay);
    }

    ButtonGroup grp = new ButtonGroup();
    for (int row = 0; row < 6; row++) {
        for (int col = 0; col < 7; col++) {
            final int day = orderedWeekdays.get(col);
            final DayButton btn = createDayButton(day, weekdays.get(day));
            btn.setMargin(new Insets(0, 0, 0, 0));
            btn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    onClickDay(btn.value);
                }
            });
            days.add(btn);
            grp.add(btn);
            panCenter.add(btn);
        }
    }
    refresh();
}

From source file:net.nosleep.superanalyzer.analysis.views.SummaryView.java

private void addStatTriple(JPanel panel, StringTriple triple) {

    JLabel wordLabel = new JLabel(triple.Name + ": ");
    wordLabel.setOpaque(false);//from  w  w w  .  ja  va  2  s. c  o m
    wordLabel.setFont(Theme.getFont(12));
    wordLabel.setHorizontalAlignment(JLabel.RIGHT);
    panel.add(wordLabel);

    JLabel wordField = new JLabel();
    wordField.setOpaque(false);
    wordField.setFont(Theme.getBoldFont(12));
    wordField.setBorder(new javax.swing.border.EmptyBorder(1, 1, 1, 1));
    wordField.setForeground(Theme.getColorSet()[0]);
    panel.add(wordField);

    wordField.setText(triple.Value);
    wordField.setToolTipText(Misc.getTooltip(triple.Info));
}

From source file:net.sourceforge.atunes.kernel.controllers.stats.StatsDialogController.java

private void setTable(JTable table, Object[] headers, Object[][] content) {
    table.setModel(new DefaultTableModel(content, headers));
    table.getColumnModel().getColumn(0).setPreferredWidth(420);
    table.getColumnModel().getColumn(0).setWidth(table.getColumnModel().getColumn(0).getWidth());
    table.getColumnModel().getColumn(2).setPreferredWidth(30);
    table.getColumnModel().getColumn(2).setWidth(table.getColumnModel().getColumn(2).getWidth());
    table.getColumnModel().getColumn(1).setCellRenderer(new SubstanceDefaultTableCellRenderer() {
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                    column);/*from w  w  w .j a  v  a 2  s.co m*/
            l.setHorizontalAlignment(SwingConstants.RIGHT);
            return l;
        }
    });
    table.getColumnModel().getColumn(2).setCellRenderer(new SubstanceDefaultTableCellRenderer() {
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                    column);
            l.setHorizontalAlignment(SwingConstants.RIGHT);
            return l;
        }
    });
}

From source file:com.intel.stl.ui.main.view.StaDetailsPanel.java

private JLabel createNumberLabel() {
    JLabel label = ComponentFactory.getH4Label(STLConstants.K0039_NOT_AVAILABLE.getValue(), Font.PLAIN);
    label.setHorizontalAlignment(JLabel.RIGHT);
    label.setVerticalAlignment(JLabel.BOTTOM);
    return label;
}