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:es.urjc.ia.fia.genericSearch.statistics.JUNGStatistics.java

@Override
public void showStatistics() {

    // Layout: tree and radial
    treeLayout = new TreeLayout<AuxVertex, ACTION>(this.tree, 35, 100);
    radialLayout = new RadialTreeLayout<AuxVertex, ACTION>(this.tree, 35, 130);

    radialLayout.setSize(new Dimension(200 * (this.tree.getHeight() + 1), 200 * (this.tree.getHeight() + 1)));

    // The BasicVisualizationServer<V,E> is parameterized by the edge types
    vv = new VisualizationViewer<AuxVertex, ACTION>(treeLayout);
    vv.setPreferredSize(new Dimension(800, 600)); //Sets the viewing area size
    vv.setBackground(Color.white); // Background color

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<AuxVertex>());
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<AuxVertex, ACTION>());

    // Setup up a new vertex to paint transformer
    Transformer<AuxVertex, Paint> vertexPaint = new Transformer<AuxVertex, Paint>() {
        @Override//from  w  w w  . j  a  v a 2 s  .c  om
        public Paint transform(AuxVertex arg0) {
            if (arg0.getState().isSolution() && arg0.isExplored()) {
                return Color.GREEN;
            } else if (arg0.isExplored()) {
                return Color.CYAN;
            } else if (arg0.isDuplicated()) {
                return Color.GRAY;
            } else {
                return Color.WHITE;
            }
        }
    };

    // Tooltip for vertex
    Transformer<AuxVertex, String> toolTipsState = new Transformer<AuxVertex, String>() {

        @Override
        public String transform(AuxVertex arg0) {
            String sortInfo = "";
            if (arg0.isExplored()) {
                if (arg0.getState().isSolution() && arg0.isExplored()) {
                    sortInfo = "<u><i>Solution state " + arg0.getExplored() + "</i></u>";
                } else {
                    sortInfo = "<u><i>Explored state " + arg0.getExplored() + "</i></u>";
                }
            } else if (arg0.isDuplicated()) {
                sortInfo = "<u><i>Duplicated state </i></u>";
            } else {
                sortInfo = "<u><i>Unexplored state</i></u>";
            }
            return "<html><p>" + sortInfo + "</p>" + "<p>State: " + arg0.getState().toString() + "</p>"
                    + "<p>Cost: " + arg0.getState().getSolutionCost() + "</p></html>";
        }

    };
    vv.setVertexToolTipTransformer(toolTipsState);

    // Tooltip for edge
    Transformer<ACTION, String> toolTipsAction = new Transformer<ACTION, String>() {

        @Override
        public String transform(ACTION arg0) {
            return "Cost: " + arg0.cost();
        }

    };
    vv.setEdgeToolTipTransformer(toolTipsAction);

    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<AuxVertex, ACTION>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<ACTION>());

    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    // Create a graph mouse and add it to the visualization component
    DefaultModalGraphMouse<State<ACTION>, ACTION> gm = new DefaultModalGraphMouse<State<ACTION>, ACTION>();
    gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    vv.addKeyListener(gm.getModeKeyListener());

    JFrame vFrame = new JFrame("Statistics Tree View");
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    /*
    vFrame.getContentPane().add(vv);
    vFrame.pack();
    vFrame.setVisible(true);
    */

    rings = new Rings();
    Container content = vFrame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    JComboBox modeBox = gm.getModeComboBox();
    modeBox.addItemListener(gm.getModeListener());
    gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JToggleButton radial = new JToggleButton("Radial");
    radial.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {

                LayoutTransition<AuxVertex, ACTION> lt = new LayoutTransition<AuxVertex, ACTION>(vv, treeLayout,
                        radialLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.addPreRenderPaintable(rings);
            } else {
                LayoutTransition<AuxVertex, ACTION> lt = new LayoutTransition<AuxVertex, ACTION>(vv,
                        radialLayout, treeLayout);
                Animator animator = new Animator(lt);
                animator.start();
                vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.removePreRenderPaintable(rings);
            }
            vv.repaint();
        }
    });

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));

    /*
     * Statistics 
     */
    JLabel stats = new JLabel();
    long totalTime = endTime.getTime() - initTime.getTime();
    stats.setText("<html>" + "<b>Total States:</b> " + this.totalStates + "<br>" + "<b>Explored States:</b> "
            + this.explorerStates + "<br>" + "<b>Duplicated States (detected):</b> " + this.duplicatedStates
            + "<br>" + "<b>Solution States:</b> " + this.solutionStates + "<br>" + "<b>Total time: </b>"
            + totalTime + " milliseconds" + "</html>");

    JPanel legend = new JPanel();
    legend.setLayout(new BoxLayout(legend, BoxLayout.Y_AXIS));

    JLabel len = new JLabel("<html><b>Lengend</b></html>");
    JLabel lexpl = new JLabel("Explored state");
    lexpl.setBackground(Color.CYAN);
    lexpl.setOpaque(true);
    JLabel lune = new JLabel("Unexplored state");
    lune.setBackground(Color.WHITE);
    lune.setOpaque(true);
    JLabel ldupl = new JLabel("Duplicated state");
    ldupl.setBackground(Color.GRAY);
    ldupl.setOpaque(true);
    JLabel lsol = new JLabel("Solution state");
    lsol.setBackground(Color.GREEN);
    lsol.setOpaque(true);

    legend.add(len);
    legend.add(lexpl);
    legend.add(lune);
    legend.add(ldupl);
    legend.add(lsol);

    JPanel controls = new JPanel();
    controls.add(stats);
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(radial);
    controls.add(scaleGrid);
    //controls.add(modeBox);
    controls.add(legend);

    content.add(controls, BorderLayout.SOUTH);

    vFrame.pack();
    vFrame.setVisible(true);
}

From source file:org.apache.taverna.activities.xpath.ui.contextualview.XPathActivityMainContextualView.java

@Override
public JComponent getMainFrame() {
    jpMainPanel = new JPanel(new GridBagLayout());
    jpMainPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 2, 4, 2),
            BorderFactory.createEmptyBorder()));

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.weighty = 0;/*from ww w .  j a  v a 2s  .  com*/

    // --- XPath Expression ---

    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(5, 5, 5, 5);
    JLabel jlXPathExpression = new JLabel("XPath Expression:");
    jlXPathExpression.setFont(jlXPathExpression.getFont().deriveFont(Font.BOLD));
    jpMainPanel.add(jlXPathExpression, c);

    c.gridx++;
    c.weightx = 1.0;
    tfXPathExpression = new JTextField();
    tfXPathExpression.setEditable(false);
    jpMainPanel.add(tfXPathExpression, c);

    // --- Label to Show/Hide Mapping Table ---

    final JLabel jlShowHideNamespaceMappings = new JLabel("Show namespace mappings...");
    jlShowHideNamespaceMappings.setForeground(Color.BLUE);
    jlShowHideNamespaceMappings.setCursor(new Cursor(Cursor.HAND_CURSOR));
    jlShowHideNamespaceMappings.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            spXPathNamespaceMappings.setVisible(!spXPathNamespaceMappings.isVisible());
            jlShowHideNamespaceMappings.setText(
                    (spXPathNamespaceMappings.isVisible() ? "Hide" : "Show") + " namespace mappings...");
            thisContextualView.revalidate();
        }
    });

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    jpMainPanel.add(jlShowHideNamespaceMappings, c);

    // --- Namespace Mapping Table ---

    xpathNamespaceMappingsTableModel = new DefaultTableModel() {
        /**
         * No cells should be editable
         */
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (false);
        }
    };
    xpathNamespaceMappingsTableModel.addColumn("Namespace Prefix");
    xpathNamespaceMappingsTableModel.addColumn("Namespace URI");

    jtXPathNamespaceMappings = new JTable();
    jtXPathNamespaceMappings.setModel(xpathNamespaceMappingsTableModel);
    jtXPathNamespaceMappings.setPreferredScrollableViewportSize(new Dimension(200, 90));
    // TODO - next line is to be enabled when Taverna is migrated to Java
    // 1.6; for now it's fine to run without this
    // jtXPathNamespaceMappings.setFillsViewportHeight(true); // makes sure
    // that when the dedicated area is larger than the table, the latter is
    // stretched vertically to fill the empty space

    jtXPathNamespaceMappings.getColumnModel().getColumn(0).setPreferredWidth(20); // set
    // relative
    // sizes of
    // columns
    jtXPathNamespaceMappings.getColumnModel().getColumn(1).setPreferredWidth(300);

    c.gridy++;
    spXPathNamespaceMappings = new JScrollPane(jtXPathNamespaceMappings);
    spXPathNamespaceMappings.setVisible(false);
    jpMainPanel.add(spXPathNamespaceMappings, c);

    // populate the view with values
    refreshView();

    return jpMainPanel;
}

From source file:drusy.ui.panels.SwitchStatePanel.java

private void addUser(String hostName, String information, long txBytes, long rxBytes) {
    JPanel panel = new JPanel();
    JLabel informationLabel = new JLabel();
    ImageIcon imageIcon;/*from   www .j a v a  2s . c  o  m*/

    //======== panel1 ========
    {
        panel.setLayout(new BorderLayout());
        panel.setBorder(new EmptyBorder(0, 10, 0, 10));

        //---- label2 ----
        if (hostName.equals("smartphone")) {
            imageIcon = Res.getImage("img/iphone-56.png");
        } else {
            imageIcon = Res.getImage("img/mac-56.png");
        }
        informationLabel.setIcon(imageIcon);
        informationLabel.setText("<html><b>" + information + "</b><br />Download: " + txBytes / 1000.0
                + " ko/s <br />Upload: " + rxBytes / 1000.0 + " ko/s</html>");
        informationLabel.setHorizontalAlignment(SwingConstants.CENTER);
        panel.add(informationLabel, BorderLayout.CENTER);
    }
    mainPanel.add(panel);
    adaptPanelSize();

    users.add(panel);
}

From source file:gov.nih.nci.nbia.StandaloneDMV3.java

private void setStatus(JLabel statusLbl, String msg, Color c) {
    statusLbl.setText(msg);
    statusLbl.setForeground(c);
}

From source file:king.flow.action.DefaultMsgSendAction.java

private void showOnComponent(Object metaNode, TLSResult result) {
    Component meta = (Component) metaNode;
    getLogger(CommunicationWorker.class.getName()).log(Level.INFO, "Display component[{0}] type : {1}",
            new Object[] { String.valueOf(meta.getId()), meta.getType().value() });
    JsonParser jsonParser;/*from w  ww. jav  a2 s  .  com*/
    JsonArray arrays;
    switch (meta.getType()) {
    case TABLE:
        try {
            jsonParser = new JsonParser();
            arrays = jsonParser.parse(result.getOkMsg()).asArray();
            JTable table = getBlock(meta.getId(), JTable.class);
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.setRowCount(0);
            for (Iterator it = arrays.iterator(); it.hasNext();) {
                JsonArray row = (JsonArray) it.next();
                Vector<String> rowData = new Vector<>();
                for (Object v : row) {
                    rowData.add(v.toString());
                }
                model.addRow(rowData);
            }
        } catch (Exception e) {
            getLogger(CommunicationWorker.class.getName()).log(Level.WARNING,
                    "Invalid array data [ {0} ] for TABLE component[{1}], \n exception is {2}",
                    new Object[] { result.getOkMsg(), String.valueOf(meta.getId()), e });
        }
        break;
    case ADVANCED_TABLE:
        try {
            jsonParser = new JsonParser();
            JsonObject jsonObj = jsonParser.parse(result.getOkMsg()).asObject();
            Integer total = jsonObj.getInt(ADVANCED_TABLE_TOTAL_PAGES);
            Integer page = jsonObj.getInt(ADVANCED_TABLE_CURRENT_PAGE);
            arrays = jsonObj.getArray(ADVANCED_TABLE_VALUE);
            getLogger(CommunicationWorker.class.getName()).log(Level.INFO,
                    "Dump JSON DATA for ADVANCED_TABLE: \n{0} \ntotal: {1} \npage: {2}",
                    new Object[] { jsonObj.toString(), total, page });
            JXMsgPanel advanceTable = getBlock(meta.getId(), JXMsgPanel.class);
            advanceTable.refreshTotalPages(total);
            advanceTable.refreshCurrentPage(page);
            advanceTable.refreshTable(arrays);
        } catch (Exception e) {
            getLogger(CommunicationWorker.class.getName()).log(Level.WARNING,
                    "Invalid complex data [ {0} ] for ADVANCED_TABLE component[{1}] \n exception is {2}",
                    new Object[] { result.getOkMsg(), String.valueOf(meta.getId()), e });
        }
        break;
    case LABEL:
        JLabel label = getBlock(meta.getId(), JLabel.class);
        if (result.getRetCode() == 0) {
            label.setText(StringEscapeUtils.unescapeHtml(result.getOkMsg()));
        } else {
            label.setText(StringEscapeUtils.unescapeHtml(result.getErrMsg()));
        }
        break;
    case TEXT_FIELD:
        JTextField textField = getBlock(meta.getId(), JTextField.class);
        if (result.getRetCode() == 0) {
            textField.setText(result.getOkMsg());
        } else {
            CommonUtil.showErrorMsg(textField.getTopLevelAncestor(), result.getErrMsg());
        }
        break;
    default:
        getLogger(CommunicationWorker.class.getName()).log(Level.WARNING,
                "Unsupported displayed component type : {0}", meta.getType());
    }
}

From source file:ComplexCellRenderer.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    Font theFont = null;//from  w  ww  . jav a2s  .c  om
    Color theForeground = null;
    Icon theIcon = 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];
        theIcon = (Icon) values[2];
        theText = (String) values[3];
    } else {
        theFont = list.getFont();
        theForeground = list.getForeground();
        theText = "";
    }
    if (!isSelected) {
        renderer.setForeground(theForeground);
    }
    if (theIcon != null) {
        renderer.setIcon(theIcon);
    }
    renderer.setText(theText);
    renderer.setFont(theFont);
    return renderer;
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.ServerPropertiesWindow.java

private Component getSingleServerSshLoginMethodComponent(final Server server) {
    sshLabel = new ChangeableLabel(getTextRepresentationOfSshSituation(server), new Executable<JLabel>() {
        @Override/* w ww  . ja  v a 2 s .  com*/
        public void run(final JLabel text) {
            final ChangeServerSshLoginMethodWindow window = new ChangeServerSshLoginMethodWindow(
                    ServerPropertiesWindow.this, server);
            window.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(final ActionEvent e) {
                    text.setText(getTextRepresentationOfSshSituation(server));
                }

            });
            window.setVisible(true);
        }
    });
    sshLabel.setBorder(null);
    return sshLabel;
}

From source file:com.m4rc310.cb.builders.ComponentBuilder.java

public void changeLabel(String ref, String newLabel) {
    try {/*from   w  w w .j  a v  a2 s .c o m*/
        JLabel label = mapLabels.get(ref);
        label.setText(newLabel);
    } catch (Exception e) {
        infoError(e);
    }
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.ServerPropertiesWindow.java

private Component getSingleServerTagComponent(final Server server) {
    final ChangeableLabel tagLabel = new ChangeableLabel(
            Utils.implode(new ArrayList<String>(server.getTags()), ", "), new Executable<JLabel>() {
                @Override//from  w ww .j av a  2s .c  o m
                public void run(final JLabel label) {
                    final TaggingWindow win = new TaggingWindow(ServerPropertiesWindow.this, server.getTags());
                    win.addWindowClosedListener(new TaggingWindow.WindowClosedListener() {
                        @Override
                        public void windowClosed(final Collection<String> newTags) {
                            label.setText(Utils.implode(new ArrayList<String>(newTags), ", "));
                            server.setTags(newTags);
                            server.store();
                        }
                    });
                    win.setVisible(true);
                }
            });
    return tagLabel;
}

From source file:projects.tgas.exec.HrDiagram.java

/**
 * Main constructor.// w  w  w.ja va  2  s  .  c  o m
 */
public HrDiagram() {

    tgasStars = TgasUtils.loadTgasCatalogue();

    method = METHOD.NAIVE;
    fMax = 1.0;

    final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values());
    methodComboBox.setSelectedItem(method);
    methodComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            method = (METHOD) methodComboBox.getSelectedItem();
            updateChart();
        }
    });

    final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f");
    fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0));
    final JLabel fLabel = new JLabel(getFLabel());
    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == fSlider) {
                // Compute fractional parallax error from slider position
                double newF = (2.0 * source.getValue() / 100.0);
                fMax = newF;
                fLabel.setText(getFLabel());
            }
            updateChart();
        }
    };
    fSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    fSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Present controls below the HR diagram
    JPanel controls = new JPanel(new GridLayout(2, 2));
    controls.add(new JLabel("Distance estimation method:"));
    controls.add(methodComboBox);
    controls.add(fLabel);
    controls.add(fSlider);

    // Initialise the ChartPanel
    updateChart();

    // Build the panel contents
    setLayout(new BorderLayout());
    add(hrDiagPanel, BorderLayout.CENTER);
    add(controls, BorderLayout.SOUTH);
}