Example usage for javax.swing JLabel setBackground

List of usage examples for javax.swing JLabel setBackground

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:org.kalypso.ogc.sensor.tableview.swing.marker.ForecastLabelMarker.java

/**
 * @see org.kalypso.ogc.sensor.tableview.swing.marker.ILabelMarker#apply(javax.swing.JLabel)
 *///from   w w w  .  j a v a  2  s.  co  m
@Override
public void apply(final JLabel label) {
    label.setBackground(FORECAST_BG);
    label.setToolTipText(FORECAST_TT);
    // label.setIcon( FORECAST_ICON );
}

From source file:org.kalypso.ogc.sensor.tableview.swing.marker.ForecastLabelMarker.java

/**
 * @see org.kalypso.ogc.sensor.tableview.swing.marker.ILabelMarker#reset(javax.swing.JLabel)
 *///from   w  ww .j  a  va  2s. co m
@Override
public void reset(final JLabel label) {
    label.setBackground(m_defaultBackground);
    label.setToolTipText(""); //$NON-NLS-1$
    label.setIcon(null);
}

From source file:org.martin.ftp.model.TCRFiles.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {

    JLabel lbl = new JLabel();
    ImageIcon icon;//  w  w  w . jav  a 2  s. co  m
    FTPFile file = files.get(row);

    if (column == 0) {
        if (file.isDirectory())
            icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/folder.png"));

        else
            icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/file.png"));

        lbl.setIcon(icon);
        lbl.setText(file.getName());
    }

    else
        lbl.setText(value.toString());

    Color bg = lbl.getBackground();

    if (isSelected)
        lbl.setBackground(Color.CYAN);

    else if (row == foundFileIndex)
        lbl.setBackground(Color.RED);

    else
        lbl.setBackground(bg);

    lbl.setOpaque(true);

    return lbl;

}

From source file:org.martin.ftp.model.TCRSearch.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {

    JLabel lbl = new JLabel();
    ImageIcon icon;/*from   w  w w .  j  av a 2  s . co  m*/
    FTPFile file = files.get(row).getFile();

    if (column == 0) {
        if (file.isDirectory())
            icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/folder.png"));

        else
            icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/file.png"));

        lbl.setIcon(icon);
        lbl.setText(file.getName());
    }

    else
        lbl.setText(value.toString());

    Color bg = lbl.getBackground();

    if (isSelected)
        lbl.setBackground(Color.CYAN);

    else
        lbl.setBackground(bg);

    lbl.setOpaque(true);

    return lbl;

}

From source file:org.nuclos.client.ui.collect.SubForm.java

private void init() {
    contentPane.add(toolbar,//ww w.  j  a  va  2  s .  co m
            toolbar.getOrientation() == JToolBar.HORIZONTAL ? BorderLayout.NORTH : BorderLayout.WEST);

    // Configure table
    scrollPane.getViewport().setBackground(subformtbl.getBackground());
    subformtbl.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    subformtbl.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    //      subformtbl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    scrollPane.getViewport().setView(subformtbl);
    JLabel labCorner = new JLabel();
    labCorner.setEnabled(false);
    labCorner.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, Color.GRAY));
    labCorner.setBackground(Color.LIGHT_GRAY);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, labCorner);

    rowHeader = createTableRowHeader(subformtbl, scrollPane);
    subformtbl.setRowHeaderTable(rowHeader);

    // subformtbl.addMouseListener(newToolbarContextMenuListener(subformtbl, subformtbl));
    addToolbarMouseListener(subformtbl, subformtbl, subformtbl);
    // scrollPane.getViewport().addMouseListener(newToolbarContextMenuListener(scrollPane.getViewport(), subformtbl));
    addToolbarMouseListener(scrollPane.getViewport(), scrollPane.getViewport(), subformtbl);
}

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

/**
 * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object, 
 *                               boolean, boolean, int, int)
 *//*from   www . j  a va  2  s . c om*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Component thisComponent = new JLabel();
    JLabel label = new JLabel();
    label.setOpaque(true);

    if (value instanceof Number) {
        MeasurementTableModel tm = (MeasurementTableModel) table.getModel();
        KeyDescription key = tm.getColumnNames().get(column);
        String k = key.getKey();
        MeasurementUnits units = tm.getUnitsType();
        Number n = (Number) value;
        String s;
        if (units.isInMicrons()) {
            UnitsObject object;
            StringBuffer buffer = new StringBuffer();
            object = UIUtilities.transformSize(n.doubleValue());
            s = twoDecimalPlaces(object.getValue());
            if (StringUtils.isNotBlank(s)) {
                buffer.append(s);
                if (!(AnnotationKeys.ANGLE.getKey().equals(k) || AnnotationDescription.ZSECTION_STRING.equals(k)
                        || AnnotationDescription.ROIID_STRING.equals(k)
                        || AnnotationDescription.TIME_STRING.equals(k))) {
                    buffer.append(object.getUnits());
                }
                if (AnnotationKeys.AREA.getKey().equals(k)) {
                    buffer = new StringBuffer();
                    object = UIUtilities.transformSquareSize(n.doubleValue());
                    s = twoDecimalPlaces(object.getValue());
                    buffer.append(s);
                    buffer.append(object.getUnits());
                }
                label.setText(buffer.toString());
            }
        } else {
            s = UIUtilities.twoDecimalPlaces(n.doubleValue());
            if (StringUtils.isNotBlank(s)) {
                label.setText(s);
            }
        }
        thisComponent = label;
    } else if (value instanceof FigureType || value instanceof String) {
        thisComponent = makeShapeIcon(label, "" + value);
    } else if (value instanceof Color) {
        label.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
        label.setBackground((Color) value);
        thisComponent = label;
    } else if (value instanceof Boolean) {
        JCheckBox checkBox = new JCheckBox();
        checkBox.setSelected((Boolean) value);
        thisComponent = checkBox;
    } else if (value instanceof ArrayList) {
        thisComponent = createList(value);
        //return list;
    }
    if (!(value instanceof Color)) {
        RendererUtils.setRowColor(thisComponent, table.getSelectedRow(), row);
        if (label != null)
            label.setBackground(thisComponent.getBackground());
    }
    return thisComponent;
}

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

/**
 * Transforms the detector metadata./*w  w w  . j a  v  a2 s. c  om*/
 * 
 * @param details The value to transform.
 */
private void transformGeneralSource(Map<String, Object> details) {
    DataComponent comp;
    JLabel label;
    JComponent area;
    String key;
    Object value;
    label = new JLabel();
    Font font = label.getFont();
    int sizeLabel = font.getSize() - 2;
    Object selected;
    List notSet = (List) details.get(EditorUtil.NOT_SET);
    details.remove(EditorUtil.NOT_SET);
    if (notSet.size() > 0 && unsetGeneral == null) {
        unsetGeneral = parent.formatUnsetFieldsControl();
        unsetGeneral.setActionID(GENERAL);
        unsetGeneral.addPropertyChangeListener(this);
    }

    Set entrySet = details.entrySet();
    Entry entry;
    Iterator i = entrySet.iterator();
    boolean set;
    while (i.hasNext()) {
        entry = (Entry) i.next();
        key = (String) entry.getKey();
        set = !notSet.contains(key);
        value = entry.getValue();
        label = UIUtilities.setTextFont(key, Font.BOLD, sizeLabel);
        label.setBackground(UIUtilities.BACKGROUND_COLOR);
        if (EditorUtil.ILLUMINATION.equals(key)) {
            selected = model.getChannelEnumerationSelected(Editor.ILLUMINATION_TYPE, (String) value);
            if (selected != null)
                illuminationBox.setSelectedItem(selected);
            else {
                set = false;
                illuminationBox.setSelectedIndex(illuminationBox.getItemCount() - 1);
            }

            illuminationBox.setEditedColor(UIUtilities.EDITED_COLOR);
            area = illuminationBox;//parent.replaceCombobox(illuminationBox);
        } else if (EditorUtil.CONTRAST_METHOD.equals(key)) {
            selected = model.getChannelEnumerationSelected(Editor.ILLUMINATION_TYPE, (String) value);
            if (selected != null)
                contrastMethodBox.setSelectedItem(selected);
            else {
                set = false;
                contrastMethodBox.setSelectedIndex(contrastMethodBox.getItemCount() - 1);
            }

            contrastMethodBox.setEditedColor(UIUtilities.EDITED_COLOR);
            area = contrastMethodBox;//parent.replaceCombobox(contrastMethodBox);
        } else if (EditorUtil.MODE.equals(key)) {
            selected = model.getChannelEnumerationSelected(Editor.MODE, (String) value);
            if (selected != null)
                modeBox.setSelectedItem(selected);
            else {
                set = false;
                modeBox.setSelectedIndex(modeBox.getItemCount() - 1);
            }
            modeBox.setEditedColor(UIUtilities.EDITED_COLOR);
            area = modeBox;//parent.replaceCombobox(modeBox);
        } else {
            if (value instanceof Number) {
                area = UIUtilities.createComponent(NumericalTextField.class, null);
                String v = "";
                if (value instanceof Double) {
                    v = "" + UIUtilities.roundTwoDecimals(((Number) value).doubleValue());
                    ((NumericalTextField) area).setNumberType(Double.class);
                } else if (value instanceof Float) {
                    v = "" + UIUtilities.roundTwoDecimals(((Number) value).doubleValue());
                    ((NumericalTextField) area).setNumberType(Float.class);
                } else
                    v = "" + value;
                ((NumericalTextField) area).setText(v);
                ((NumericalTextField) area).setEditedColor(UIUtilities.EDITED_COLOR);
            } else {
                area = UIUtilities.createComponent(OMETextArea.class, null);
                if (value == null || value.equals("")) {
                    set = false;
                    value = AnnotationUI.DEFAULT_TEXT;
                }
                ((OMETextArea) area).setEditable(false);
                ((OMETextArea) area).setText((String) value);
                ((OMETextArea) area).setEditedColor(UIUtilities.EDITED_COLOR);
            }
        }
        area.setEnabled(!set);
        comp = new DataComponent(label, area);
        comp.setEnabled(false);
        comp.setSetField(!notSet.contains(key));
        fieldsGeneral.put(key, comp);
    }
}

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

/** Initializes the components. */
private void initComponents() {
    IconManager icons = IconManager.getInstance();
    Icon icon = icons.getIcon(IconManager.DOWNLOAD);
    downloadButton = new JButton(icon);
    downloadButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    downloadButton.setOpaque(false);/*w ww.j  a v  a 2 s .  com*/
    UIUtilities.unifiedButtonLookAndFeel(downloadButton);
    downloadButton.setToolTipText("Download the metadata file.");
    downloadButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            download();
        }
    });
    toolBar = buildToolBar();
    toolBar.setBackground(UIUtilities.BACKGROUND_COLOR);
    JXBusyLabel label = new JXBusyLabel(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
    label.setBackground(UIUtilities.BACKGROUND_COLOR);
    label.setBusy(true);
    JPanel p = new JPanel();
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(label);
    p.add(Box.createHorizontalStrut(5));
    JLabel l = new JLabel("Loading metadata");
    l.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.add(l);
    statusBar = UIUtilities.buildComponentPanel(p);
    statusBar.setBackground(UIUtilities.BACKGROUND_COLOR);
    setBackground(UIUtilities.BACKGROUND_COLOR);
    setLayout(new BorderLayout(0, 0));
    add(statusBar, BorderLayout.NORTH);
}

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

/** 
 * Builds and lays out the UI.//w  ww . ja va 2s .  c  o m
 * 
 * @param components The components to lay out.
 */
private void buildGUI(Map<String, List<String>> components) {
    //Now lay out the elements
    JPanel p = new JPanel();
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    String key;
    List<String> l;
    Entry<String, List<String>> entry;
    Iterator<Entry<String, List<String>>> i = components.entrySet().iterator();
    JPanel row;
    JLabel label;
    p.add(new JSeparator());
    while (i.hasNext()) {
        entry = i.next();
        key = entry.getKey();
        l = entry.getValue();
        if (!CollectionUtils.isEmpty(l)) {
            label = UIUtilities.setTextFont(key);
            label.setBackground(UIUtilities.BACKGROUND_COLOR);
            row = UIUtilities.buildComponentPanel(label);
            row.setBackground(UIUtilities.BACKGROUND_COLOR);
            p.add(row);
            p.add(createTable(l));
        }
    }
    removeAll();
    add(toolBar, BorderLayout.NORTH);
    add(p, BorderLayout.CENTER);
    revalidate();
    repaint();
}

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

/**
 * Reads the file and displays the result in a table.
 * //  w  ww.  j a  v a  2 s . c om
 * @param file The file to read.
 */
void setOriginalFile(File file) {
    metadataLoaded = true;
    if (file == null) {
        JLabel l = new JLabel("Metadata could not be retrieved.");
        l.setBackground(UIUtilities.BACKGROUND_COLOR);
        statusBar = UIUtilities.buildComponentPanel(l);
        statusBar.setBackground(UIUtilities.BACKGROUND_COLOR);
        removeAll();
        add(statusBar, BorderLayout.NORTH);
        return;
    }
    downloadButton.setEnabled(file.length() != 0);
    try {
        BufferedReader input = new BufferedReader(new FileReader(file));
        Map<String, List<String>> components = new LinkedHashMap<String, List<String>>();
        try {
            String line = null;
            List<String> l;
            String key = null;
            int start = 0;
            while ((line = input.readLine()) != null) {
                if (line.contains("=")) {
                    if (!StringUtils.isBlank(key)) {
                        l = components.get(key);
                        if (l != null)
                            l.add(line);
                    }
                } else {
                    line = line.trim();
                    if (line.length() > 0) {
                        start = getStart(line);
                        key = line.substring(start, line.length() - 1);
                        if (!StringUtils.isBlank(key))
                            components.put(key, new ArrayList<String>());
                    }
                }
            }
        } finally {
            input.close();
        }
        buildGUI(components);
        file.delete();
    } catch (IOException e) {
        file.delete();
        JLabel l = new JLabel("Loading metadata");
        l.setBackground(UIUtilities.BACKGROUND_COLOR);
        statusBar = UIUtilities.buildComponentPanel(l);
        statusBar.setBackground(UIUtilities.BACKGROUND_COLOR);
        removeAll();
        add(statusBar, BorderLayout.NORTH);
        Logger logger = MetadataViewerAgent.getRegistry().getLogger();
        LogMessage msg = new LogMessage();
        msg.print("An error occurred while reading metadata file.");
        msg.print(e);
        logger.error(this, msg);
    }
}