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:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java

/** Builds and lays out the UI. */
private void buildGUI() {
    removeAll();/*w w w  .  j a  va2 s . co m*/

    JLabel l = new JLabel();
    Font f = l.getFont();
    int size = f.getSize() - 1;
    content.removeAll();
    content.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 1, 2, 1);
    c.anchor = GridBagConstraints.WEST;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.HORIZONTAL;

    if (!model.isAnnotationLoaded()) {
        l.setText("Annotation could not be loaded");
        content.add(l, c);
        return;
    }

    if (model.isMultiSelection()) {
        Object refObject = model.getRefObject();
        StringBuffer buffer = new StringBuffer();
        buffer.append("Annotate the selected ");
        buffer.append(model.getObjectTypeAsString(refObject));
        buffer.append("s");
        l.setText(buffer.toString());
        content.add(l, c);
        c.gridy++;
    }

    // filters
    content.add(createBar(filterButton, null), c);
    c.gridy++;

    // rating
    c.gridwidth = 1;
    c.gridx = 0;
    c.weightx = 0;
    c.fill = GridBagConstraints.NONE;
    JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.add(UIUtilities.setTextFont("Rating:", Font.BOLD, size));
    p.add(createBar(unrateButton, null));
    content.add(p, c);
    c.gridx = 1;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.add(rating);
    p.add(Box.createHorizontalStrut(2));
    p.add(otherRating);
    content.add(p, c);
    c.gridy++;

    // tags
    c.gridx = 0;
    p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.add(UIUtilities.setTextFont("Tags:", Font.BOLD, size));
    p.add(createBar(addTagsButton, removeTagsButton));
    content.add(p, c);
    c.gridy++;
    content.add(tagsPane, c);
    c.gridy++;

    // attachment
    c.gridx = 0;
    c.gridwidth = 2;
    p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.add(UIUtilities.setTextFont("Attachments:", Font.BOLD, size));
    p.add(createBar(addDocsButton, removeDocsButton));
    content.add(p, c);
    c.gridy++;
    content.add(docRef, c);
    c.gridy++;

    if (!model.isMultiSelection()) {
        mapsPane.reload(filter);
        content.add(mapsPane, c);
        c.gridy++;
    }

    // other
    if (!CollectionUtils.isEmpty(model.getAllOtherAnnotations())) {
        p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
        p.setBackground(UIUtilities.BACKGROUND_COLOR);
        p.add(UIUtilities.setTextFont("Others:", Font.BOLD, size));
        p.add(createBar(null, removeOtherAnnotationsButton));
        content.add(p, c);
        c.gridy++;
        content.add(otherPane, c);
    }

    add(content, BorderLayout.CENTER);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.DocComponent.java

/**
 * Displays information about the attachment.
 * /*from  ww  w  .  j a va  2  s.c o m*/
 * @param invoker The component where the clicks occurred.
 * @param p The location of the mouse pressed.
 */
private void displayInformation(JComponent invoker, Point p) {
    String text = label.getToolTipText();
    if (text == null || text.trim().length() == 0)
        return;
    JComponent comp;
    if (preview != null) {
        comp = preview;
    } else {
        JLabel l = new JLabel();
        l.setText(text);
        comp = l;
    }

    TinyDialog d = new TinyDialog(null, comp, TinyDialog.CLOSE_ONLY);
    d.setModal(true);
    d.getContentPane().setBackground(UIUtilities.BACKGROUND_COLOUR_EVEN);
    SwingUtilities.convertPointToScreen(p, invoker);
    d.pack();
    d.setLocation(p);
    d.setVisible(true);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Lays out the plate fields.// w ww.  ja  v a2 s  .  co m
 * 
 * @param plate The plate to handle.
 * @return See above.
 */
private JPanel layoutPlateContent(PlateData plate) {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    content.setLayout(new GridBagLayout());
    JLabel l = new JLabel();
    Font font = l.getFont();
    int size = font.getSize() - 2;

    Map<JLabel, JComponent> components = new LinkedHashMap<JLabel, JComponent>();
    String v = plate.getPlateType();
    JLabel value;
    if (v != null && v.trim().length() > 0) {
        l = UIUtilities.setTextFont(EditorUtil.TYPE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        value.setFont(font.deriveFont(font.getStyle(), size));
        value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
        value.setText(v);
        components.put(l, value);
    }
    l = UIUtilities.setTextFont(EditorUtil.EXTERNAL_IDENTIFIER, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = plate.getExternalIdentifier();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);
    l = UIUtilities.setTextFont(EditorUtil.STATUS, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = plate.getStatus();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);
    layoutComponents(content, components);
    return content;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Lays out the well fields.// ww  w.  j a  v  a 2 s  .c  om
 * 
 * @param well The well to handle.
 * @return See above.
 */
private JPanel layoutWellContent(WellData well) {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    content.setLayout(new GridBagLayout());
    JLabel l = new JLabel();
    Font font = l.getFont();
    int size = font.getSize() - 2;

    Map<JLabel, JComponent> components = new LinkedHashMap<JLabel, JComponent>();
    String v = well.getWellType();
    JLabel value;
    if (v != null && v.trim().length() > 0) {
        l = UIUtilities.setTextFont(EditorUtil.TYPE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        value.setFont(font.deriveFont(font.getStyle(), size));
        value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
        value.setText(v);
        components.put(l, value);
    }
    l = UIUtilities.setTextFont(EditorUtil.EXTERNAL_DESCRIPTION, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = well.getExternalDescription();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);
    l = UIUtilities.setTextFont(EditorUtil.STATUS, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = well.getStatus();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);
    layoutComponents(content, components);
    return content;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Lays out the screen fields./*  w  w w .ja  v a  2 s  .  c  o m*/
 * 
 * @param screen The screen to handle.
 * @return See above.
 */
private JPanel layoutScreenContent(ScreenData screen) {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    content.setLayout(new GridBagLayout());
    JLabel l = new JLabel();
    Font font = l.getFont();
    int size = font.getSize() - 2;

    Map<JLabel, JComponent> components = new LinkedHashMap<JLabel, JComponent>();

    l = UIUtilities.setTextFont("Protocol Identifier:", Font.BOLD, size);
    JLabel value = UIUtilities.createComponent(null);
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    String v = screen.getProtocolIdentifier();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    l = UIUtilities.setTextFont("Protocol Description:", Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = screen.getProtocolDescription();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    l = UIUtilities.setTextFont("ReagentSet Identifier:", Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = screen.getReagentSetIdentifier();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    l = UIUtilities.setTextFont("ReagentSet Description:", Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    value.setFont(font.deriveFont(font.getStyle(), size));
    v = screen.getReagentSetDescripion();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    layoutComponents(content, components);
    return content;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Returns the pixels size as a string.//w  ww  . j a  v a2s . c o  m
 * 
 * @param details The map to convert.
 * @param component The component displaying the information.
 * @return See above.
 */
private String formatPixelsSize(Map details, JLabel component) {
    String x = (String) details.get(EditorUtil.PIXEL_SIZE_X);
    String y = (String) details.get(EditorUtil.PIXEL_SIZE_Y);
    String z = (String) details.get(EditorUtil.PIXEL_SIZE_Z);
    Double dx = null, dy = null, dz = null;
    boolean number = true;
    NumberFormat nf = NumberFormat.getInstance();
    String units = null;
    UnitsObject o;
    try {
        dx = Double.parseDouble(x);
        o = EditorUtil.transformSize(dx);
        units = o.getUnits();
        dx = o.getValue();
    } catch (Exception e) {
        number = false;
    }
    try {
        dy = Double.parseDouble(y);
        o = EditorUtil.transformSize(dy);
        if (units == null)
            units = o.getUnits();
        dy = o.getValue();
    } catch (Exception e) {
        number = false;
    }
    try {
        dz = Double.parseDouble(z);
        o = EditorUtil.transformSize(dz);
        if (units == null)
            units = o.getUnits();
        dz = o.getValue();
    } catch (Exception e) {
        number = false;
    }

    String label = "Pixels Size (";
    String value = "";
    String tooltip = "<html><body>";
    if (dx != null && dx.doubleValue() > 0) {
        value += nf.format(dx);
        tooltip += "X: " + x + "<br>";
        label += "X";
    }
    if (dy != null && dy.doubleValue() > 0) {
        if (value.length() == 0)
            value += nf.format(dy);
        else
            value += "x" + nf.format(dy);
        ;
        tooltip += "Y: " + y + "<br>";
        label += "Y";
    }
    if (dz != null && dz.doubleValue() > 0) {
        if (value.length() == 0)
            value += nf.format(dz);
        else
            value += "x" + nf.format(dz);
        tooltip += "Z: " + z + "<br>";
        label += "Z";
    }
    label += ") ";
    if (!number) {
        component.setForeground(AnnotationUI.WARNING);
        component.setToolTipText("Values stored in the file...");
    } else {
        component.setToolTipText(tooltip);
    }
    if (value.length() == 0)
        return null;
    component.setText(value);
    if (units == null)
        units = UnitsObject.MICRONS;
    label += units;
    return label;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
  * Builds the panel hosting the information
  * //ww w  .  j  a  v  a 2 s. c  o  m
  * @param details The information to display.
  * @param image     The image of reference.
  * @return See above.
  */
private JPanel buildContentPanel(Map details, ImageData image) {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    c.gridy = 0;
    c.gridx = 0;
    JLabel l = new JLabel();
    Font font = l.getFont();
    int size = font.getSize() - 2;
    JLabel label = UIUtilities.setTextFont(EditorUtil.ARCHIVED, Font.BOLD, size);
    JCheckBox box = new JCheckBox();
    box.setEnabled(false);
    box.setBackground(UIUtilities.BACKGROUND);
    box.setSelected(model.isArchived());
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(box, c);
    c.gridy++;
    c.gridx = 0;
    label = UIUtilities.setTextFont(EditorUtil.ACQUISITION_DATE, Font.BOLD, size);
    JLabel value = UIUtilities.createComponent(null);
    String v = model.formatDate(image);
    value.setText(v);
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    c.gridx = 0;
    try { //just to be on the save side
        label = UIUtilities.setTextFont(EditorUtil.IMPORTED_DATE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        v = UIUtilities.formatShortDateTime(image.getInserted());
        value.setText(v);
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
        c.gridy++;
    } catch (Exception e) {

    }
    label = UIUtilities.setTextFont(EditorUtil.XY_DIMENSION, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    v = (String) details.get(EditorUtil.SIZE_X);
    v += " x ";
    v += (String) details.get(EditorUtil.SIZE_Y);
    value.setText(v);
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.PIXEL_TYPE, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setText((String) details.get(EditorUtil.PIXEL_TYPE));
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);

    value = UIUtilities.createComponent(null);
    String s = formatPixelsSize(details, value);
    if (s != null) {
        c.gridy++;
        label = UIUtilities.setTextFont(s, Font.BOLD, size);
        c.gridx = 0;
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
    }
    //parse modulo T.
    Map<Integer, ModuloInfo> modulo = model.getModulo();
    ModuloInfo moduloT = modulo.get(ModuloInfo.T);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.Z_T_FIELDS, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    v = (String) details.get(EditorUtil.SECTIONS);
    v += " x ";
    if (moduloT != null) {
        String time = (String) details.get(EditorUtil.TIMEPOINTS);
        int t = Integer.parseInt(time);
        v += "" + (t / moduloT.getSize());
    } else {
        v += (String) details.get(EditorUtil.TIMEPOINTS);
    }
    value.setText(v);
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    if (moduloT != null) {
        label = UIUtilities.setTextFont(EditorUtil.SMALL_T_VARIABLE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        value.setText("" + moduloT.getSize());
        c.gridx = 0;
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
        c.gridy++;
    }
    if (!model.isNumerousChannel() && model.getRefObjectID() > 0) {
        label = UIUtilities.setTextFont(EditorUtil.CHANNELS, Font.BOLD, size);
        c.gridx = 0;
        c.anchor = GridBagConstraints.NORTHEAST;
        content.add(label, c);
        c.anchor = GridBagConstraints.CENTER;
        c.gridx++;
        content.add(editChannel, c);
        c.gridx++;
        content.add(channelsPane, c);
    }
    JPanel p = UIUtilities.buildComponentPanel(content);
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    return p;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.util.SaveResultsDialog.java

/**
 * Builds and lays out the elements indicating what to save.
 *
 * @return See above./*from   w w w . j  a va2 s . com*/
 */
private JPanel buildContents() {
    JPanel buttons = new JPanel();
    buttons.add(UIUtilities.setTextFont("Save results for"));
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS));
    ButtonGroup group = new ButtonGroup();
    JRadioButton b = new JRadioButton("Image from current window");
    b.setSelected(activeWindow);
    buttons.add(b);
    group.add(b);
    b.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            activeWindow = (e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    b = new JRadioButton("Images from all image windows");
    b.setSelected(activeWindow);
    buttons.add(b);
    group.add(b);
    buttons.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE));
    buttons.add(UIUtilities.setTextFont("Save"));
    buttons.add(roi);
    buttons.add(table);
    JPanel row = new JPanel();
    row.setLayout(new FlowLayout(FlowLayout.LEFT));
    JLabel l = new JLabel();
    l.setText("Measurements File Name: ");
    row.add(l);
    row.add(nameField);
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(UIUtilities.buildComponentPanel(buttons));
    p.add(row);
    return p;
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java

/** 
 * Builds and lays out the details of the script e.g.
 * authors, contact, version.//from  w  ww .j  av  a 2  s.  co m
 * 
 * @return See above.
 */
private JPanel buildScriptDetails() {
    String[] authors = script.getAuthors();
    String contact = script.getContact();
    String version = script.getVersion();
    if (authors == null && contact == null && version == null)
        return null;
    JPanel p = new JPanel();
    p.setBackground(BG_COLOR);
    double[] columns = { TableLayout.PREFERRED, 5, TableLayout.FILL };
    TableLayout layout = new TableLayout();
    layout.setColumn(columns);
    p.setLayout(layout);
    int row = 0;
    JLabel l;
    if (authors != null && authors.length > 0) {
        l = UIUtilities.setTextFont("Authors:");
        StringBuffer buffer = new StringBuffer();
        int n = authors.length - 1;
        for (int i = 0; i < authors.length; i++) {
            buffer.append(authors[i]);
            if (i < n)
                buffer.append(", ");
        }
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(l, "0," + row);
        l = new JLabel();
        l.setText(buffer.toString());
        p.add(l, "2," + row);
        row++;
    }
    if (StringUtils.isNotBlank(contact)) {
        l = UIUtilities.setTextFont("Contact:");
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(l, "0," + row);
        l = new JLabel();
        l.setText(contact);
        p.add(l, "2," + row);
        row++;
    }
    if (StringUtils.isNotBlank(version)) {
        l = UIUtilities.setTextFont("Version:");
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(l, "0," + row);
        l = new JLabel();
        l.setText(version);
        p.add(l, "2," + row);
    }
    if (p.getComponentCount() == 0)
        return null;
    return p;
}

From source file:org.openmicroscopy.shoola.env.ui.ActivityComponent.java

/**
 * Returns the tool bar./*from   w  w  w . ja  v  a 2s  . co m*/
 * 
 * @return See above.
 */
private JComponent createToolBar() {
    toolBar = new JToolBar();
    toolBar.setOpaque(false);
    toolBar.setFloatable(false);
    toolBar.setBorder(null);
    buttonIndex = 0;
    toolBar.add(exceptionButton);
    toolBar.add(Box.createHorizontalStrut(5));
    buttonIndex = 2;
    toolBar.add(cancelButton);
    JLabel l = new JLabel();
    Font f = l.getFont();
    l.setForeground(UIUtilities.LIGHT_GREY.darker());
    l.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2));
    String s = UIUtilities.formatShortDateTime(null);
    String[] values = s.split(" ");
    if (values.length > 1) {
        String v = values[1];
        if (values.length > 2)
            v += " " + values[2];
        l.setText(v);
        toolBar.add(Box.createHorizontalStrut(5));
        toolBar.add(l);
        toolBar.add(Box.createHorizontalStrut(5));
    }
    return toolBar;
}