javax.swing.JComponent#setForeground ( )源码实例Demo

下面列出了javax.swing.JComponent#setForeground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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;
}
 
源代码2 项目: ghidra   文件: PythonCodeCompletionFactory.java
/**
 * 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);
}
 
源代码3 项目: stendhal   文件: StyledMenuItemUI.java
@Override
public void installUI(JComponent component) {
	super.installUI(component);

	component.setBorder(style.getBorder());
	component.setOpaque(false);
	component.setFont(style.getFont());
	component.setForeground(style.getForeground());
}
 
源代码4 项目: netbeans   文件: TableUISupport.java
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;
}
 
源代码5 项目: jeveassets   文件: ColorSettings.java
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());
	}
}
 
源代码6 项目: stendhal   文件: StyledCheckBoxUI.java
@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);
	}
}
 
源代码7 项目: material-ui-swing   文件: MaterialToolBarUI.java
@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);
}
 
源代码8 项目: stendhal   文件: StyledTableUI.java
@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());
}
 
源代码9 项目: material-ui-swing   文件: MaterialPopupMenuUI.java
@Override
public void uninstallUI(JComponent c) {

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

	super.uninstallUI(c);
}
 
源代码10 项目: material-ui-swing   文件: MaterialSliderUI.java
@Override
public void uninstallUI(JComponent c) {

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

	super.uninstallUI(c);
}
 
源代码11 项目: settlers-remake   文件: StoneBackgroundLabel.java
@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);
}
 
源代码12 项目: stendhal   文件: StyledSliderUI.java
@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());
}
 
@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));
}
 
@Override
public void uninstallUI(JComponent c) {

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

	super.uninstallUI(c);
}
 
源代码15 项目: ccu-historian   文件: SortButtonRenderer.java
/**
 * 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;
}
 
源代码16 项目: javamoney-examples   文件: RenderHelper.java
/**
 * 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);
  }
}
 
源代码17 项目: netbeans   文件: Coloring.java
/** 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);
                }
            }
        }
    }
}
 
public static void decreaseTextBrightness(JComponent c) {
    Color color = (Color) c.getClientProperty("mouseover_brightness");
    c.setForeground(color);
}
 
源代码19 项目: stendhal   文件: StyledSeparatorUI.java
@Override
public void installUI(JComponent separator) {
	super.installUI(separator);
	separator.setBackground(style.getHighLightColor());
	separator.setForeground(style.getShadowColor());
}
 
源代码20 项目: nmonvisualizer   文件: TableColumnChooser.java
@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;
}