Example usage for javax.swing JLabel setText

List of usage examples for javax.swing JLabel setText

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "Defines the single line of text this component will display.")
public void setText(String text) 

Source Link

Document

Defines the single line of text this component will display.

Usage

From source file:Main.java

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    JLabel l = (JLabel) renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
            hasFocus);/*ww w . java2 s.  c  o  m*/
    if (value instanceof DefaultMutableTreeNode) {
        check.setEnabled(tree.isEnabled());
        check.setFont(tree.getFont());
        Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
        if (userObject instanceof CheckBoxNode) {
            CheckBoxNode node = (CheckBoxNode) userObject;
            l.setText(node.text);
            check.setSelected(node.selected);
        }
        p.add(l);
        return p;
    }
    return l;
}

From source file:MainClass.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    Font theFont = null;/*from w  w w.j  a  va 2 s .  c  o m*/
    Color theForeground = null;
    String theText = null;

    JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected,
            cellHasFocus);

    if (value instanceof Object[]) {
        Object values[] = (Object[]) value;
        theFont = (Font) values[0];
        theForeground = (Color) values[1];
        theText = (String) values[2];
    } else {
        theFont = list.getFont();
        theForeground = list.getForeground();
        theText = "";
    }
    if (!isSelected) {
        renderer.setForeground(theForeground);
    }
    renderer.setText(theText);
    renderer.setFont(theFont);
    return renderer;
}

From source file:com.funambol.json.admin.JsonConnectorConfigPanel.java

/**
 * Create the panel/*from ww w.j  av  a2  s.  c  o m*/
 */
private void init() {

    JLabel title, serverLabel;
    JPanel seccPanel;
    JPanel behaviourOnErrorsPanel;

    title = new JLabel();
    seccPanel = new JPanel();
    behaviourOnErrorsPanel = new JPanel();

    serverLabel = new JLabel();
    serverValue = new JTextField();

    setLayout(null);

    title.setFont(titlePanelFont);
    title.setText("Funambol Json Connector");
    title.setBounds(new Rectangle(14, 5, 316, 28));
    title.setAlignmentX(SwingConstants.CENTER);
    title.setBorder(new TitledBorder(""));

    seccPanel.setLayout(null);
    seccPanel.setBorder(new TitledBorder("HTTP Server Configuration"));

    serverLabel.setText("Server:");
    seccPanel.add(serverLabel);
    serverLabel.setBounds(10, 20, 116, 15);
    seccPanel.add(serverValue);
    serverValue.setBounds(150, 20, 220, 19);
    serverValue.setFont(defaultFont);

    add(seccPanel);
    seccPanel.setBounds(10, 50, 380, 70);

    //the ssl option panel

    behaviourOnErrorsPanel.setBorder(new TitledBorder("Behaviour on errors"));
    behaviourOnErrorsPanel.setLayout(null);

    stopSyncOnFatalError.setText("Stop sync on fatal errors");
    stopSyncOnFatalError.setBounds(10, 25, 200, 15);

    behaviourOnErrorsPanel.add(stopSyncOnFatalError);

    add(behaviourOnErrorsPanel);
    behaviourOnErrorsPanel.setBounds(10, 130, 380, 60);

    confirmButton.setFont(defaultFont);
    confirmButton.setText("Save");
    add(confirmButton);
    confirmButton.setBounds(160, 200, 70, 25);

    confirmButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                JsonConnectorConfigPanel.this.actionPerformed(new ActionEvent(JsonConnectorConfigPanel.this,
                        ACTION_EVENT_UPDATE, event.getActionCommand()));
            } catch (Exception e) {
                notifyError(new AdminException(e.getMessage()));
            }
        }
    });

    //
    // Setting font...
    //
    Component[] components = getComponents();
    for (int i = 0; (components != null) && (i < components.length); ++i) {
        components[i].setFont(defaultFont);
    }

    //
    // We add it as the last one so that the font won't be changed
    //
    add(title);
}

From source file:de.wusel.partyplayer.gui.PartyPlayer.java

private Component createSongPanel() {
    final SongsTableModel model = new SongsTableModel(playerModel, settings, this);

    table = new JXTable(model) {

        @Override//from  ww  w.ja  v  a2  s  .  co m
        public String getToolTipText(MouseEvent event) {
            int viewRowIndex = rowAtPoint(event.getPoint());
            if (viewRowIndex != -1) {
                int modelIndex = convertRowIndexToModel(viewRowIndex);
                SongWrapper songFromList = playerModel.getSongFromList(modelIndex);
                return songFromList.getFileName();
            }
            return super.getToolTipText(event);
        }
    };

    table.setAutoCreateRowSorter(true);
    String numberColumnName = getText("table.songs.column.number.label");
    table.getColumn(numberColumnName).setMaxWidth(25);
    table.getColumn(numberColumnName).setResizable(false);
    TableSortController sorter = (TableSortController) table.getRowSorter();
    sorter.setComparator(2, new SongComparator());

    table.getColumn(numberColumnName).setCellRenderer(new SubstanceDefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                    column);
            if (value != null)
                label.setText(((SongWrapper) value).getTrackNumber() + "");
            return label;
        }
    });

    table.getColumn(getText("table.songs.column.duration.label"))
            .setCellRenderer(new SubstanceDefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected,
                            hasFocus, row, column);
                    if (value != null)
                        label.setText(Util.getTimeString((Double) value));
                    return label;
                }
            });

    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                addSongToPlaylist(
                        playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow())));
            }
        }
    });

    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                addSongToPlaylist(
                        playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow())));
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    table.setFillsViewportHeight(true);
    return scrollPane;
}

From source file:ca.phon.app.query.report.ReportTreeCellRenderer.java

@Override
public Component getTreeCellRendererComponent(JTree arg0, Object arg1, boolean arg2, boolean arg3, boolean arg4,
        int arg5, boolean arg6) {
    JLabel lbl = (JLabel) super.getTreeCellRendererComponent(arg0, arg1, arg2, arg3, arg4, arg5, arg6);

    Section section = (Section) arg1;//from w  ww.  ja v a 2s .  c o  m

    if (arg1 == arg0.getModel().getRoot()) {
        lbl.setIcon(rptIcon);
    } else {
        lbl.setIcon(icons.get(section.getClass()));
    }

    String lblText = StringUtils.strip(section.getName());
    if (lblText == null || lblText.length() == 0) {
        lblText = "<html><i>Untitled</i></html>";
    }
    lbl.setText(lblText);

    //      if(arg1 instanceof ReportDesign) {
    //         ReportDesign report = (ReportDesign)arg1;
    //         lbl.setText(report.getName());
    //         lbl.setIcon(rptIcon);
    //      } else {
    //         Section section = (Section)arg1;
    //         lbl.setIcon(icons.get(section.getClass()));
    //         
    //         
    //         lbl.setText(section.getName());
    ////         if(section instanceof Group) {
    ////            lbl.setText("Group : " + section.getName());
    ////         } else {
    ////            lbl.setText("Section : " + section.getName());
    ////         }
    //      }

    return lbl;
}

From source file:com.atlassian.theplugin.idea.config.serverconfig.GenericServerConfigForm.java

/**
 * Method generated by IntelliJ IDEA GUI Designer
 * >>> IMPORTANT!! <<<
 * DO NOT edit this method OR call it in your code!
 *
 * @noinspection ALL/*  ww  w  .  ja v  a 2 s  .  c  o m*/
 */
private void $$$setupUI$$$() {
    rootComponent = new JPanel();
    rootComponent.setLayout(new GridBagLayout());
    final JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayoutManager(7, 3, new Insets(0, 0, 0, 0), -1, -1));
    GridBagConstraints gbc;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    rootComponent.add(panel1, gbc);
    serverName = new JTextField();
    serverName.setText("");
    panel1.add(serverName,
            new GridConstraints(1, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    final JLabel label1 = new JLabel();
    label1.setHorizontalAlignment(4);
    label1.setHorizontalTextPosition(4);
    label1.setText("Server Name:");
    label1.setDisplayedMnemonic('S');
    label1.setDisplayedMnemonicIndex(0);
    panel1.add(label1,
            new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(80, -1),
                    new Dimension(92, 16), null, 0, false));
    serverUrl = new JTextField();
    panel1.add(serverUrl,
            new GridConstraints(2, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    username = new JTextField();
    panel1.add(username,
            new GridConstraints(3, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    password = new JPasswordField();
    panel1.add(password,
            new GridConstraints(4, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    final JLabel label2 = new JLabel();
    label2.setHorizontalAlignment(4);
    label2.setText("Server URL:");
    label2.setDisplayedMnemonic('U');
    label2.setDisplayedMnemonicIndex(7);
    panel1.add(label2,
            new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(80, -1),
                    new Dimension(92, 16), null, 0, false));
    final JLabel label3 = new JLabel();
    label3.setHorizontalAlignment(4);
    label3.setText("Username:");
    label3.setDisplayedMnemonic('N');
    label3.setDisplayedMnemonicIndex(4);
    panel1.add(label3,
            new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null,
                    new Dimension(92, 16), null, 0, false));
    final JLabel label4 = new JLabel();
    label4.setHorizontalAlignment(4);
    label4.setText("Password:");
    label4.setDisplayedMnemonic('P');
    label4.setDisplayedMnemonicIndex(0);
    panel1.add(label4,
            new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null,
                    new Dimension(92, 16), null, 0, false));
    testConnection = new JButton();
    testConnection.setText("Test Connection");
    testConnection.setMnemonic('T');
    testConnection.setDisplayedMnemonicIndex(0);
    panel1.add(testConnection,
            new GridConstraints(5, 2, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    //      chkPasswordRemember = new JCheckBox();
    //      chkPasswordRemember.setSelected(true);
    //      chkPasswordRemember.setText("Remember Password");
    //      chkPasswordRemember.setMnemonic('R');
    //      chkPasswordRemember.setDisplayedMnemonicIndex(0);
    //      panel1.add(chkPasswordRemember, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
    //            GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED,
    //            null, null, null, 0, false));
    cbEnabled = new JCheckBox();
    cbEnabled.setEnabled(false);
    cbEnabled.setHorizontalTextPosition(11);
    cbEnabled.setText("Server Enabled");
    cbEnabled.setMnemonic('E');
    cbEnabled.setDisplayedMnemonicIndex(7);
    panel1.add(cbEnabled,
            new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(115, 25), null, 0, false));
    useDefault = new JCheckBox();
    useDefault.setText("Use Default Credentials");
    panel1.add(useDefault,
            new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    final JPanel spacer1 = new JPanel();
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.VERTICAL;
    rootComponent.add(spacer1, gbc);
    label1.setLabelFor(serverName);
    label2.setLabelFor(serverUrl);
    label3.setLabelFor(username);
    label4.setLabelFor(password);
}

From source file:MyViewChooser.java

public MyViewChooser() {
    super("File View Test Frame");
    setSize(350, 200);/*from  ww w  .  j  av  a  2  s .co m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    parent = this;

    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();

            // Ok, set up our own file view for the chooser
            chooser.setFileView(new ThumbNailFileView(MyViewChooser.this));

            int option = chooser.showOpenDialog(parent);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You chose " + chooser.getSelectedFile().getName());
            } else {
                statusbar.setText("You cancelled.");
            }
        }
    });

    c.add(openButton);
    c.add(statusbar);
}

From source file:ecg.ecgshow.ECGShowUI.java

private void createHeartRateData(long timeZone) {
    HeartRatedatas = new short[2];
    HeartRateData = new JPanel();
    //HeartRateData.setLayout(new BorderLayout());
    HeartRateData.setLayout(new FlowLayout());
    HeartRateData.setBounds(0, 0, (int) (WIDTH * 0.14), (int) (HEIGHT * 0.15));
    HeartRateData.setBackground(Color.BLACK);

    JLabel jLabel1 = new JLabel("---");
    if (HeartRatedatas[0] == 0x00 || HeartRatedatas == null) {
        jLabel1.setText("---");
    } else {/*from  w  w w  .  j  a  v  a 2  s.co  m*/
        jLabel1.setText(Short.toString((short) HeartRatedatas[0]));
    }

    jLabel1.setFont(loadFont("LED.tff", (float) (HEIGHT * 0.070)));
    jLabel1.setBackground(Color.BLACK);
    jLabel1.setForeground(Color.GREEN);
    jLabel1.setBounds(0, 0, 100, 100);
    jLabel1.setOpaque(true); //??

    JLabel jLabelName = new JLabel(" ");
    jLabelName.setFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.020)));
    jLabelName.setBackground(Color.BLACK);
    jLabelName.setForeground(new Color(237, 65, 43));
    jLabelName.setBounds(0, 0, 100, 100);
    jLabelName.setOpaque(true); //??

    JLabel jLabelUnit = new JLabel(" bpm");
    jLabelUnit.setFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.020)));
    jLabelUnit.setBackground(Color.BLACK);
    jLabelUnit.setForeground(Color.GREEN);
    jLabelUnit.setBounds(0, 0, 100, 100);
    jLabelUnit.setOpaque(true); //??

    HeartRateData.add(jLabelName);
    HeartRateData.add(jLabel1);
    HeartRateData.add(jLabelUnit);
    System.out.println("HeartRatedatas" + Short.toString(HeartRatedatas[0]));
    ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            if (HeartRatedatas[0] == -100 || HeartRatedatas[0] == 156 || HeartRatedatas[0] == 0) {
                jLabel1.setText("--");
            } else {
                jLabel1.setText(String.valueOf(HeartRatedatas[0]));
            }
            HeartRateData.repaint();
        }
    }, 0, 3, TimeUnit.SECONDS);
}

From source file:ecg.ecgshow.ECGShowUI.java

private void createBloodOxygenData(long timeZone) {
    BloodOxygendatas = new short[2];
    BloodOxygenData = new JPanel();
    BloodOxygenData.setLayout(new FlowLayout());
    BloodOxygenData.setBounds(0, 0, (int) (WIDTH * 0.14), (int) (HEIGHT * 0.15));
    BloodOxygenData.setBackground(Color.BLACK);

    JLabel jLabel1 = new JLabel("---");
    if (BloodOxygendatas[0] == 0x00 || BloodOxygendatas == null) {
        jLabel1.setText("---");
    } else {/*from   www  .j  a v a2  s.  c  o  m*/
        jLabel1.setText(Short.toString((short) BloodOxygendatas[0]));
    }
    System.out.println("BloodOxygendatas" + Short.toString(BloodOxygendatas[0]));
    jLabel1.setFont(loadFont("LED.tff", (float) (HEIGHT * 0.070)));
    jLabel1.setBackground(Color.BLACK);
    jLabel1.setForeground(Color.GREEN);
    jLabel1.setBounds(0, 0, 100, 100);
    jLabel1.setOpaque(true);

    JLabel jLabelName = new JLabel(" ");
    jLabelName.setFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.020)));
    jLabelName.setBackground(Color.BLACK);
    jLabelName.setForeground(new Color(237, 65, 43));
    jLabelName.setBounds(0, 0, 100, 100);
    jLabelName.setOpaque(true); //??

    JLabel jLabelUnit = new JLabel(" %");
    jLabelUnit.setFont(new Font("SansSerif", 0, (int) (HEIGHT * 0.020)));
    jLabelUnit.setBackground(Color.BLACK);
    jLabelUnit.setForeground(Color.GREEN);
    jLabelUnit.setBounds(0, 0, 100, 100);
    jLabelUnit.setOpaque(true); //??

    BloodOxygenData.add(jLabelName);
    BloodOxygenData.add(jLabel1);
    BloodOxygenData.add(jLabelUnit);

    ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            if (BloodOxygendatas[0] == 0 || HeartRatedatas[0] == -100) {
                jLabel1.setText("--");
            } else {
                jLabel1.setText(String.valueOf(BloodOxygendatas[0]));
            }
            BloodOxygenData.repaint();
        }
    }, 0, 3, TimeUnit.SECONDS);
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/** Creates new form FrequencyDomainPanel */
public FrequencyDomainPanel() {
    initComponents();//from w w w .  j a v a 2 s  .  c  om

    initGraph();

    headerPanel.setBackgroundPainter(Common.getHeaderPainter());

    JPanel holderPanel = new JPanel() {
        @Override
        public void paint(Graphics g) {

            if (plot.getDomainAxis().isAutoRange()) {
                plot.getDomainAxis().setAutoRange(false);
                Range newDomain = new Range(0, FMCUartClient.BLOCK_SIZE - 1);
                plot.getDomainAxis().setRange(newDomain, true, false);
            }

            if (plot.getRangeAxis().isAutoRange()) {
                plot.getRangeAxis().setAutoRange(false);
                Range newRange = new Range(-50, 70);
                plot.getRangeAxis().setRange(newRange, true, false);
            }

            super.paint(g);
        }
    };
    holderPanel.setLayout(new BorderLayout());
    holderPanel.add(chartPanel, BorderLayout.CENTER);
    this.mainPanel.add(holderPanel, BorderLayout.CENTER);

    windowComboBox.setModel(new DefaultComboBoxModel(WindowFunction.values()));
    windowComboBox.setSelectedItem(WindowFunction.BLACKMAN_HARRIS);
    windowComboBox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {

            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (c instanceof JLabel && value instanceof WindowFunction) {
                JLabel l = (JLabel) c;
                WindowFunction cw = (WindowFunction) value;
                l.setText(cw.getName());
            }

            return c;
        }

    });

    graphLabel.setUI(new BasicLabelUI());
    alphaLabel.setUI(new BasicLabelUI());
    windowLabel.setUI(new BasicLabelUI());
}