Java Code Examples for javax.swing.JComponent#setForeground()

The following examples show how to use javax.swing.JComponent#setForeground() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    JComponent comp = (JComponent) super.getTableCellRendererComponent(
            table, value, isSelected, hasFocus, row, col);
    List<Integer> dupList = getDuplicate(row);
    if (!dupList.isEmpty()) {
        comp.setForeground(errorColor);
        comp.setToolTipText("Duplicate with Step " + dupList);
    } else if (col == ExecutionStep.HEADERS.Status.getIndex()) {
        if ("Passed".equals(value)) {
            comp.setForeground(Color.GREEN.darker());
        } else if ("Failed".equals(value)) {
            comp.setForeground(errorColor);
        } else {
            comp.setForeground(table.getForeground());
        }
    } else {
        comp.setForeground(table.getForeground());
        comp.setToolTipText(null);
    }
    return comp;
}
 
Example 2
/**
 * Creates a new CodeCompletion from the given Python objects.
 * 
 * @param description description of the new CodeCompletion
 * @param insertion what will be inserted to make the code complete
 * @param pyObj a Python Object
 * @return A new CodeCompletion from the given Python objects.
 */
public static CodeCompletion newCodeCompletion(String description, String insertion,
		PyObject pyObj) {
	JComponent comp = null;

	if (pyObj != null) {
		if (includeTypes) {
			/* append the class name to the end of the description */
			String className = getSimpleName(pyObj.getClass());
			if (pyObj instanceof PyInstance) {
				/* get the real class */
				className = getSimpleName(((PyInstance) pyObj).instclass.__name__);
			}
			else if (className.startsWith("Py")) {
				/* strip off the "Py" */
				className = className.substring("Py".length());
			}
			description = description + " (" + className + ")";
		}

		comp = new GDLabel(description);
		Iterator<Class<?>> iter = classes.iterator();
		while (iter.hasNext()) {
			Class<?> testClass = iter.next();
			if (testClass.isInstance(pyObj)) {
				comp.setForeground(classToColorMap.get(testClass));
				break;
			}
		}
	}
	return new CodeCompletion(description, insertion, comp);
}
 
Example 3
@Override
public void installUI(JComponent component) {
	super.installUI(component);

	component.setBorder(style.getBorder());
	component.setOpaque(false);
	component.setFont(style.getFont());
	component.setForeground(style.getForeground());
}
 
Example 4
Source Project: netbeans   File: TableUISupport.java    License: Apache License 2.0 5 votes vote down vote up
public Component getTableCellRendererComponent(JTable jTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    boolean joinTable = false;
    boolean validClass = true;
    boolean existentUpdate = false;
    String problemDisplayName = null;

    if (jTable.getModel() instanceof TableClassNamesModel) {
        TableClassNamesModel model = (TableClassNamesModel)jTable.getModel();
        Table table = model.getTableAt(row);
        joinTable = table.isJoin();
        if (column == 1) {
            existentUpdate = table.getDisabledReason() instanceof Table.ExistingDisabledReason;
            validClass = model.isValidClass(table);
            if (!validClass) {
                problemDisplayName = model.getProblemDisplayName(table);
            }
        }
    }

    Object realValue = null;
    if (joinTable && column == 1) {
        realValue = NbBundle.getMessage(TableUISupport.class, "LBL_JoinTable");
    } else {
        realValue = value;
    }
    JComponent component = (JComponent)super.getTableCellRendererComponent(jTable, realValue, isSelected, hasFocus, row, column);
    component.setEnabled(!joinTable && !existentUpdate);
    component.setToolTipText(joinTable ? NbBundle.getMessage(TableUISupport.class, "LBL_JoinTableDescription") : problemDisplayName);
    component.setForeground((validClass) ? nonErrorForeground : errorForeground);
   
    return component;
}
 
Example 5
public static void config(JComponent component, ColorEntry colorEntry) {
	Color foreground = foreground(colorEntry);
	Color background = background(colorEntry);
	if (background != null) {
		component.setOpaque(true);
		component.setBackground(background);
	} else {
		component.setOpaque(false);
	}
	if (foreground != null) {
		component.setForeground(foreground);
	} else {
		component.setForeground(Colors.COMPONENT_FOREGROUND.getColor());
	}
}
 
Example 6
@Override
public void installUI(JComponent component) {
	super.installUI(component);
	component.setForeground(style.getForeground());
	component.setOpaque(false);
	component.setFont(style.getFont().deriveFont(Font.BOLD));

	if (component instanceof JCheckBox) {
		JCheckBox checkBox = (JCheckBox) component;
		checkBox.setIcon(defaultIcon);
		checkBox.setSelectedIcon(defaultSelectedIcon);
		checkBox.setDisabledIcon(disabledIcon);
		checkBox.setDisabledSelectedIcon(disabledSelectedIcon);
	}
}
 
Example 7
Source Project: material-ui-swing   File: MaterialToolBarUI.java    License: MIT License 5 votes vote down vote up
@Override
public void uninstallUI(JComponent c) {

	c.setFont (null);
	c.setBackground (null);
	c.setForeground (null);
	c.setBorder (null);
	c.setCursor(null);

	this.dockingColor = null;
	this.floatingColor = null;
	super.uninstallUI(c);
}
 
Example 8
@Override
public void installUI(JComponent table) {
	super.installUI(table);
	table.setForeground(style.getForeground());
	table.setBackground(style.getPlainColor());
	table.setFont(style.getFont().deriveFont(Font.BOLD));
	this.table.setGridColor(style.getShadowColor());
}
 
Example 9
Source Project: material-ui-swing   File: MaterialPopupMenuUI.java    License: MIT License 5 votes vote down vote up
@Override
public void uninstallUI(JComponent c) {

	c.setFont (null);
	c.setBackground (null);
	c.setForeground (null);
	c.setBorder (null);
	c.setCursor(null);

	super.uninstallUI(c);
}
 
Example 10
Source Project: material-ui-swing   File: MaterialSliderUI.java    License: MIT License 5 votes vote down vote up
@Override
public void uninstallUI(JComponent c) {

	c.setFont (null);
	c.setBackground (null);
	c.setForeground (null);
	c.setBorder (null);
	c.setCursor(null);

	super.uninstallUI(c);
}
 
Example 11
Source Project: settlers-remake   File: StoneBackgroundLabel.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	c.setForeground(foregroundColor);
	c.setFont(UIDefaults.FONT);
	c.setBorder(BorderFactory.createEmptyBorder(paddingTop, (int) (BORDER[7/* left */].getWidth() * BORDER_FACTOR),
			paddingBottom, (int) (BORDER[3/* right */].getWidth() * BORDER_FACTOR)));
	c.setOpaque(false);
}
 
Example 12
@Override
public void installUI(JComponent slider) {
	super.installUI(slider);
	// A pixmap style will not tile right if we try to draw the background
	// here
	slider.setOpaque(false);
	slider.setForeground(style.getForeground());
	slider.setBackground(style.getShadowColor());
}
 
Example 13
@Override
public void installUI (JComponent c) {
	super.installUI (c);

	c.setBackground(UIManager.getColor("RadioButtonMenuItem.background"));
	c.setForeground(UIManager.getColor("RadioButtonMenuItem.foreground"));
	c.setBorder(UIManager.getBorder("RadioButtonMenuItem.border"));
	c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
 
Example 14
@Override
public void uninstallUI(JComponent c) {

	c.setFont (null);
	c.setBackground (null);
	c.setForeground (null);
	c.setBorder (null);
	c.setCursor(null);

	super.uninstallUI(c);
}
 
Example 15
/**
 * Returns the renderer component.
 *
 * @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;
}
 
Example 16
Source Project: javamoney-examples   File: RenderHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This method customizes the component with a predefined look.
 *
 * @param component The component to customize.
 * @param row The row the component is in, or index the component is at.
 * @param isSelected Whether or not the component is currently selected.
 * @param useBorder Whether or not to put a border around the component.
 */
public
static
void
setLookFor(JComponent component, int row, boolean isSelected, boolean useBorder)
{
  Border border = null;
  Color bgColor = null;
  Color fgColor = null;

  if(isSelected == true)
  {
    border = SELECTED;
    bgColor = COLOR_SELECTION_BACKGROUND;
    fgColor = COLOR_SELECTION_TEXT;
  }
  else
  {
    if((row % 2) == 0)
    {
      border = NOT_SELECTED_EVEN;
      bgColor = COLOR_TABLE_ROW_EVEN;
    }
    else
    {
      border = NOT_SELECTED_ODD;
      bgColor = COLOR_TABLE_ROW_ODD;
    }

    fgColor = COLOR_TEXT;
  }

  // Customize component.
  component.setBackground(bgColor);
  component.setFont(FONT);
  component.setForeground(fgColor);
  component.setOpaque(true);

  if(useBorder == true)
  {
    component.setBorder(border);
  }
}
 
Example 17
Source Project: netbeans   File: Coloring.java    License: Apache License 2.0 4 votes vote down vote up
/** Apply this coloring to component colors/font.
* The underline and strikeThrough line colors have no effect here.
*/
public void apply(JComponent c) {
    // Possibly change font
    if (font != null) {
        if (fontMode == FONT_MODE_DEFAULT) {
            c.setFont(font);

        } else { // non-default font-mode
            Font origFont = c.getFont();
            if (origFont != null) {
                synchronized (cacheLock) {
                    Font f = (Font)fontAndForeColorCache.get(origFont);
                    if (f == null) {
                        f = modifyFont(origFont);
                        fontAndForeColorCache.put(origFont, f);
                    }
                    c.setFont(f);
                }
            }
        }
    }

    // Possibly change fore-color
    if (foreColor != null) {
        if (!hasAlpha(foreColor)) {
            c.setForeground(foreColor);

        } else { // non-default fore color-mode
            Color origForeColor = c.getForeground();
            if (origForeColor != null) {
                synchronized (cacheLock) {
                    Color fc = (Color)fontAndForeColorCache.get(origForeColor);
                    if (fc == null) {
                        fc = modifyForeColor(origForeColor);
                        fontAndForeColorCache.put(origForeColor, fc);
                    }
                    c.setForeground(fc);
                }
            }
        }
    }

    // Possibly change back-color
    if (backColor != null) {
        if (!hasAlpha(backColor)) {
            c.setBackground(backColor);

        } else { // non-default back color-mode
            Color origBackColor = c.getBackground();
            if (origBackColor != null) {
                synchronized (cacheLock) {
                    Color bc = (Color)backColorCache.get(origBackColor);
                    if (bc == null) {
                        bc = modifyBackColor(origBackColor);
                        backColorCache.put(origBackColor, bc);
                    }
                    c.setBackground(bc);
                }
            }
        }
    }
}
 
Example 18
public static void decreaseTextBrightness(JComponent c) {
    Color color = (Color) c.getClientProperty("mouseover_brightness");
    c.setForeground(color);
}
 
Example 19
@Override
public void installUI(JComponent separator) {
	super.installUI(separator);
	separator.setBackground(style.getHighLightColor());
	separator.setForeground(style.getShadowColor());
}
 
Example 20
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
        boolean hasFocus, int row, int column) {

    JComponent renderer = null;

    boolean red = false;

    // note 'row' here since each column in the summary table is a row in this chooser table
    if (!tableModel.canDisableColumn(row)) {
        JLabel required = new JLabel("Required");

        required.setHorizontalAlignment(SwingConstants.CENTER);

        if (!isSelected) {
            red = true;
        }

        renderer = required;
    }
    else {
        Boolean b = (Boolean) value;

        JCheckBox checkBox = new JCheckBox();
        checkBox.setHorizontalAlignment(SwingConstants.CENTER);

        if (b != null) {
            checkBox.setSelected(b);
        }

        renderer = checkBox;
    }

    // the default check box renderer does not use the correct, alternating colors
    // this code is modified from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6723524
    Component other = (JLabel) table.getDefaultRenderer(String.class).getTableCellRendererComponent(table,
            value, isSelected, hasFocus, row, column);
    java.awt.Color bg = other.getBackground();

    if (isSelected) {
        renderer.setForeground(table.getSelectionForeground());
        renderer.setBackground(table.getSelectionBackground());
    }
    else {
        renderer.setForeground(red ? java.awt.Color.RED : other.getForeground());
        renderer.setBackground(new java.awt.Color(bg.getRed(), bg.getGreen(), bg.getBlue()));
    }
    renderer.setOpaque(true);

    return renderer;
}