Java Code Examples for java.awt.Component#setForeground()

The following examples show how to use java.awt.Component#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 getListCellRendererComponent(JList<?> list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) {
    Component component =
            super.getListCellRendererComponent(list, value, index,
                                               isSelected, cellHasFocus);
    switch (((ServiceItem) value).state) {
        case REMOVED:
            component.setBackground(Color.RED);
            component.setForeground(Color.WHITE);
            break;
        case ADDED:
            component.setBackground(Color.GREEN);
            component.setForeground(Color.BLACK);
            break;
        case UNCHANGED:
        default:
            break;
    }
    return component;
}
 
Example 2
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,int row, int column) {
	Component comp = new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	comp.setForeground(Color.BLACK);
	
	
	
	if ((Integer) value > 0)
		comp.setBackground(Color.GREEN);
	else if(isSelected)
		comp.setBackground(table.getSelectionBackground());
	else
		comp.setBackground(table.getBackground());
	
	
	return comp;
}
 
Example 3
Source Project: netbeans   File: BeansCompletionItem.java    License: Apache License 2.0 6 votes vote down vote up
public Component getPaintComponent(javax.swing.JList list, boolean isSelected, boolean cellHasFocus) {
    Component ret = getPaintComponent(isSelected);
    if (ret == null) {
        return null;
    }
    if (isSelected) {
        ret.setBackground(list.getSelectionBackground());
        ret.setForeground(list.getSelectionForeground());
    } else {
        ret.setBackground(list.getBackground());
        ret.setForeground(list.getForeground());
    }
    ret.getAccessibleContext().setAccessibleName(getItemText());
    ret.getAccessibleContext().setAccessibleDescription(getItemText());
    return ret;
}
 
Example 4
Source Project: netbeans   File: SettingsTab.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer,
        int rowIndex, int vColIndex) {
    Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
    Color bgColor = getBackground();
    Color bgColorDarker = UnitTable.getDarkerColor(bgColor);
    
    if (isRowSelected(rowIndex)) {
        c.setForeground(getSelectionForeground());
    } else {
        c.setForeground(getForeground());
    }
    
    if (!isCellSelected(rowIndex, vColIndex)) {
        if (rowIndex % 2 == 0) {
            c.setBackground(bgColorDarker);
        } else {
            c.setBackground(bgColor);
        }
    }
    
    return c;
}
 
Example 5
@Override
public Component getTableCellRendererComponent( JTable   table,
                                                Object   value,
                                                boolean  isSelected,
                                                boolean  hasFocus,
                                                int      rowIndex,
                                                int      columnIndex )
{
    MergeTableModel  model = (MergeTableModel) table.getModel();
    String  leftProperty = propertyOn( model.leftLineAtRow(rowIndex) );
    String  rightProperty = propertyOn( model.rightLineAtRow(rowIndex) );
    boolean  same = leftProperty.equals( rightProperty );
    Component  c = super.getTableCellRendererComponent( table,
                                                        value,
                                                        isSelected,
                                                        hasFocus,
                                                        rowIndex,
                                                        columnIndex );
    c.setForeground( same ? Color.BLACK : Color.RED );
    return c;
}
 
Example 6
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (value instanceof PhpFrameworkProvider) {
        FrameworkModelItem item = model.getItem(row);

        Component defaultRenderer = super.getTableCellRendererComponent(table, item.getFramework().getName(), isSelected, false, row, column);
        if (item.isValid()) {
            defaultRenderer.setForeground(NORMAL_COLOR);
        } else {
            defaultRenderer.setForeground(ERROR_COLOR);
        }
        return defaultRenderer;
    } else if (value instanceof Boolean && booleanRenderer != null) {
        return booleanRenderer.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    }
    return super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
}
 
Example 7
/**
 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object,
 * boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (column == GameStatisticsGUI.SCORE_COLUMN) {
        component.setFont(component.getFont().deriveFont(Font.BOLD));
    }
    component.setForeground(round.getPlayer(row).getColor().textColor());
    component.setBackground(column == 0 ? GameStatisticsGUI.HEADER_COLOR : GameStatisticsGUI.BODY_COLOR);
    return component;
}
 
Example 8
Source Project: cstc   File: Operation.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void changeFontColor(Container container, Color color) {
	for (Component comp : container.getComponents()) {
		if (comp instanceof JLabel || comp.equals(errorArea)) {
			comp.setForeground(color);
		} else if (comp instanceof Container) {
			changeFontColor((Container) comp, color);
		}
	}
}
 
Example 9
@Override
protected Component getAnotherObject() {
    Component component = new MyComponent();
    component.setForeground(Color.BLACK);
    component.setFont(new Font(null, Font.ITALIC, 6));
    return component;
}
 
Example 10
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 11
Source Project: jaamsim   File: DefaultCellRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
                                               boolean isSelected, boolean hasFocus,
                                               int row, int column) {
	Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

	if (row == table.getSelectedRow())
		cell.setBackground(FrameBox.TABLE_SELECT);
	else
		cell.setBackground(null);

	cell.setForeground(null);
	this.setBorder(border);
	return cell;
}
 
Example 12
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	Component listCellRendererComponent = super.getListCellRendererComponent(list, value, index, isSelected,
			cellHasFocus);
	boolean isLoading = LOADING == value;
	if (EMPTY == value || isLoading) {
		listCellRendererComponent.setBackground(list.getBackground());
		listCellRendererComponent.setForeground(UIManager.getColor("Label.disabledForeground"));
		listCellRendererComponent.setEnabled(false);
		setDisabledIcon(isLoading ? loadingIcon : null);
		setText(value.toString());
	}
	return listCellRendererComponent;
}
 
Example 13
Source Project: netbeans   File: ProfilerTable.java    License: Apache License 2.0 5 votes vote down vote up
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    Component c = super.prepareRenderer(renderer, row, column);
    
    boolean cEnabled = c.isEnabled();
    if (!cEnabled) c.setForeground(UIManager.getColor("TextField.inactiveForeground")); // NOI18N
    
    boolean isSelected = isCellSelected(row, column);
    
    if (isSelected && isEnabled()) {
        boolean focusOwner = !shadeUnfocusedSelection || super.isFocusOwner();
        if (cEnabled) c.setForeground(focusOwner ? getSelectionForeground() : UIUtils.getUnfocusedSelectionForeground());
        c.setBackground(focusOwner ? getSelectionBackground() : UIUtils.getUnfocusedSelectionBackground());
    } else if (!isEnabled()) {
        if (cEnabled) c.setForeground(UIManager.getColor("TextField.inactiveForeground")); // NOI18N
        c.setBackground(UIManager.getColor("TextField.inactiveBackground")); // NOI18N
    } else {
        if (cEnabled) c.setForeground(getForeground());
        c.setBackground(background(row, column));
    }
    
    c.move(0, 0);
    
    int col = convertColumnIndexToModel(column);        
    if (!isCustomRendering() && isScrollableColumn(col)) {
        int prefWidth = getColumnPreferredWidth(col);
        return getScrollableRenderer(c, col, prefWidth);
    } else {
        return c;
    }
}
 
Example 14
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 15
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 16
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 17
@Override
protected Component getAnotherObject() {
    Component component = new MyComponent();
    component.setForeground(Color.BLACK);
    component.setFont(new Font(null, Font.ITALIC, 6));
    return component;
}
 
Example 18
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
	Component comp = super.getTableCellEditorComponent(table, value, isSelected, row, column);
	if (!reader.getAttributeColumn(column - 1).isActivated()) {
		comp.setForeground(Color.LIGHT_GRAY);
	} else {
		comp.setForeground(Color.BLACK);
	}
	return comp;
}
 
Example 19
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 20
/******************************************************************
 * TRANSLUCENT THEME
 ******************************************************************/

//
// default cell renderer
//
private Component prepareThemedRenderer(TableCellRenderer renderer, int row, int column) {

    final Component cell = super.prepareRenderer(renderer, row, column);
    final MagicCardDefinition card = tableModel.getCardDef(row);
    final boolean isRowSelected = isRowSelected(row);

    /*
    Set text color.
    */
    cell.setForeground(card.isInvalid()
            ? Color.GRAY
            : ColorHelper.getOppositeColor(defaultForeColor)
    );

    /*
    default cell properties
    */
    final int ordinal = convertColumnIndexToModel(column);
    if (CardTableColumn.values()[ordinal] != CardTableColumn.Cost) {
        if (cell instanceof JComponent) {
            final JComponent jc = (JComponent) cell;
            jc.setBorder(isRowSelected ? SELECTED_BORDER : NO_FOCUS_BORDER);
            jc.setOpaque(false);
        }
    }


    /*
    Highlight row on mouse over.
    */
    if (row == mouseOverRow) {
        cell.setForeground(MagicStyle.getRolloverColor());
    }

    return cell;
}