Example usage for javax.swing JComponent setForeground

List of usage examples for javax.swing JComponent setForeground

Introduction

In this page you can find the example usage for javax.swing JComponent setForeground.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.")
public void setForeground(Color fg) 

Source Link

Document

Sets the foreground color of this component.

Usage

From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JTableInfoForCMFolder.java

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

    JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
            column);/*from w ww . ja  va  2 s .  co  m*/
    if (value == null) {
        comp.setToolTipText(null);
        return comp;
    }

    comp.setToolTipText(String.valueOf(value));

    if (row >= table.getRowCount()) {
        log.debug("row > table.getRowCount()");
        return comp;
    }

    switch (column) {

    case TableModelForCMFolder.COL_COMPONENT_NAME:
    case TableModelForCMFolder.COL_LICENSE_NAME:
        setHorizontalAlignment(SwingConstants.LEFT);
        break;

    case TableModelForCMFolder.COL_VERSION_NAME:
    case TableModelForCMFolder.COL_IDENTIFIED:
    case TableModelForCMFolder.COL_STATUS:
    case TableModelForCMFolder.COL_PENDING:
        setHorizontalAlignment(SwingConstants.CENTER);
        break;
    }
    int pendingHits = 0;
    int identifiedHits = 0;

    if (table.getValueAt(row, TableModelForCMFolder.COL_PENDING) != null) {
        pendingHits = Tools
                .transStringToInteger(table.getValueAt(row, TableModelForCMFolder.COL_PENDING).toString());
    }
    if (table.getValueAt(row, TableModelForCMFolder.COL_IDENTIFIED) != null) {
        identifiedHits = Tools
                .transStringToInteger(table.getValueAt(row, TableModelForCMFolder.COL_IDENTIFIED).toString());
    }
    if (identifiedHits > 0 && pendingHits == 0) {
        comp.setFont(new Font("Arial", Font.BOLD, 12));
        comp.setForeground(NORMAL_COLOR);
    } else if (identifiedHits == 0 && pendingHits == 0) {
        comp.setForeground(GRAY_COLOR);
    } else {
        comp.setForeground(NORMAL_COLOR);
    }

    return comp;
}

From source file:SortableTable.java

/**
 * Returns the renderer component./*from   w  ww .  j av  a  2  s  .c  om*/
 *
 * @param table      the table.
 * @param value      the value.
 * @param isSelected selected?
 * @param hasFocus   focussed?
 * @param row        the row.
 * @param column     the column.
 * @return the renderer.
 */
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected,
        final boolean hasFocus, final int row, final int column) {

    if (table == null) {
        throw new NullPointerException("Table must not be null.");
    }

    final JComponent component;
    final SortableTableModel model = (SortableTableModel) table.getModel();
    final int cc = table.convertColumnIndexToModel(column);
    final boolean isSorting = (model.getSortingColumn() == cc);
    final boolean isAscending = model.isAscending();

    final JTableHeader header = table.getTableHeader();
    final boolean isPressed = (cc == this.pressedColumn);

    if (this.useLabels) {
        final JLabel label = getRendererLabel(isSorting, isAscending);
        label.setText((value == null) ? "" : value.toString());
        component = label;
    } else {
        final JButton button = getRendererButton(isSorting, isAscending);
        button.setText((value == null) ? "" : value.toString());
        button.getModel().setPressed(isPressed);
        button.getModel().setArmed(isPressed);
        component = button;
    }

    if (header != null) {
        component.setForeground(header.getForeground());
        component.setBackground(header.getBackground());
        component.setFont(header.getFont());
    }
    return component;
}

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

/**
 * Builds the panel hosting the user's details.
 * /*  w w w. j a  va 2  s.  c o  m*/
 * @return See above.
 */
private JPanel buildContentPanel() {
    ExperimenterData user = (ExperimenterData) model.getRefObject();
    boolean editable = model.isUserOwner(user);
    if (!editable)
        editable = MetadataViewerAgent.isAdministrator();
    details = EditorUtil.convertExperimenter(user);
    JPanel content = new JPanel();
    content.setBorder(BorderFactory.createTitledBorder("User"));
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    Entry<String, String> entry;
    Iterator<Entry<String, String>> i = details.entrySet().iterator();
    JComponent label;
    JTextField area;
    String key, value;
    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    //Add log in name but cannot edit.
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;//end row
    c.fill = GridBagConstraints.HORIZONTAL;
    content.add(buildProfileCanvas(), c);
    c.gridy++;
    c.gridx = 0;
    label = EditorUtil.getLabel(EditorUtil.DISPLAY_NAME, true);
    label.setBackground(UIUtilities.BACKGROUND_COLOR);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE;//reset to default
    c.weightx = 0.0;
    content.add(label, c);
    c.gridx++;
    content.add(Box.createHorizontalStrut(5), c);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;//end row
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    loginArea.setText(user.getUserName());
    loginArea.setEnabled(false);
    loginArea.setEditable(false);
    if (MetadataViewerAgent.isAdministrator() && !model.isSystemUser(user.getId()) && !model.isSelf()) {
        loginArea.setEnabled(true);
        loginArea.getDocument().addDocumentListener(this);
    }
    content.add(loginArea, c);
    while (i.hasNext()) {
        ++c.gridy;
        c.gridx = 0;
        entry = i.next();
        key = entry.getKey();
        value = entry.getValue();
        label = EditorUtil.getLabel(key, EditorUtil.FIRST_NAME.equals(key) || EditorUtil.LAST_NAME.equals(key));
        area = new JTextField(value);
        area.setBackground(UIUtilities.BACKGROUND_COLOR);
        area.setEditable(editable);
        area.setEnabled(editable);
        if (editable)
            area.getDocument().addDocumentListener(this);
        items.put(key, area);
        label.setBackground(UIUtilities.BACKGROUND_COLOR);
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE;//reset to default
        c.weightx = 0.0;
        content.add(label, c);
        c.gridx++;
        content.add(Box.createHorizontalStrut(5), c);
        c.gridx++;
        c.gridwidth = GridBagConstraints.REMAINDER;//end row
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 1.0;
        content.add(area, c);
    }
    c.gridx = 0;
    c.gridy++;
    label = EditorUtil.getLabel(EditorUtil.DEFAULT_GROUP, false);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE;//reset to default
    c.weightx = 0.0;
    content.add(label, c);
    c.gridx++;
    content.add(Box.createHorizontalStrut(5), c);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    content.add(groupsBox, c);
    c.gridy++;
    content.add(permissionsPane, c);
    c.gridx = 0;
    c.gridy++;
    label = EditorUtil.getLabel(EditorUtil.GROUP_OWNER, false);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE; //reset to default
    c.weightx = 0.0;
    content.add(label, c);
    c.gridx++;
    content.add(Box.createHorizontalStrut(5), c);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    c.fill = GridBagConstraints.NONE;
    c.weightx = 1.0;
    content.add(ownerBox, c);
    if (activeBox.isVisible()) {
        c.gridx = 0;
        c.gridy++;
        label = EditorUtil.getLabel(EditorUtil.ACTIVE, false);
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE;
        c.weightx = 0.0;
        content.add(label, c);
        c.gridx++;
        content.add(Box.createHorizontalStrut(5), c);
        c.gridx++;
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.fill = GridBagConstraints.NONE;
        c.weightx = 1.0;
        content.add(activeBox, c);
    }
    if (adminBox.isVisible()) {
        c.gridx = 0;
        c.gridy++;
        label = EditorUtil.getLabel(EditorUtil.ADMINISTRATOR, false);
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE;
        c.weightx = 0.0;
        content.add(label, c);
        c.gridx++;
        content.add(Box.createHorizontalStrut(5), c);
        c.gridx++;
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.fill = GridBagConstraints.NONE;
        c.weightx = 1.0;
        content.add(adminBox, c);
    }
    c.gridx = 0;
    c.gridy++;
    content.add(Box.createHorizontalStrut(10), c);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.MANDATORY_DESCRIPTION, Font.ITALIC);
    label.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR);
    c.weightx = 0.0;
    content.add(label, c);
    return content;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Creates a new label./*from  w w  w. jav a 2s . c  o m*/
 * 
 * @param type    The type of component to create. Default type is JLabel.
 * @param color The foreground color if not <code>null</code>.
 * @return See above.
 */
public static JComponent createComponent(Class type, Color color) {
    if (type == null)
        type = JLabel.class;
    JComponent comp = null;
    if (JLabel.class.equals(type))
        comp = new JLabel();
    else if (OMETextField.class.equals(type))
        comp = new OMETextField();
    else if (OMETextArea.class.equals(type))
        comp = new OMETextArea();
    else if (NumericalTextField.class.equals(type)) {
        comp = new NumericalTextField();
        ((NumericalTextField) comp).setHorizontalAlignment(JTextField.LEFT);
        ((NumericalTextField) comp).setNegativeAccepted(true);
        comp.setBorder(null);
    }

    if (comp == null)
        comp = new JLabel();
    comp.setBackground(BACKGROUND_COLOR);
    Font font = comp.getFont();
    comp.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
    if (color != null)
        comp.setForeground(color);
    return comp;
}