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

The following are Jave code examples for showing how to use setForeground() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: RendererPropertyDisplayer.java   View Source Code Vote up 6 votes
protected void prepareRenderer(JComponent comp) {
    comp.setBackground(getBackground());
    comp.setForeground(getForeground());
    comp.setBounds(0, 0, getWidth(), getHeight());

    JComponent innermost;

    if ((innermost = findInnermostRenderer(comp)) instanceof JComboBox) {
        if (comp.getLayout() != null) {
            comp.getLayout().layoutContainer(comp);
        }
    }

    if (!isTableUI() && ((InplaceEditor) comp).supportsTextEntry()) {
        innermost.setBackground(PropUtils.getTextFieldBackground());
        innermost.setForeground(PropUtils.getTextFieldForeground());
    }
}
 
Example 2
Project: PTEAssistant   File: UserTableHeaderCellRenderer.java   View Source Code Vote up 6 votes
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
    String valueStr = (String) value;
    JLabel label = new JLabel(valueStr);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    selectBox.setHorizontalAlignment(SwingConstants.CENTER);
    selectBox.setBorderPainted(true);
    JComponent component = (column == 0) ? selectBox : label;

    component.setForeground(tableHeader.getForeground());
    component.setBackground(tableHeader.getBackground());
    component.setFont(tableHeader.getFont());
    component.setBorder(UIManager.getBorder("TableHeader.cellBorder"));

    return component;
}
 
Example 3
Project: Cognizant-Intelligent-Test-Scripter   File: TestSetValidator.java   View Source Code Vote up 6 votes
@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 4
Project: xdman   File: XDMButtonUI.java   View Source Code Vote up 6 votes
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	if (c instanceof JButton) {
		btn = (JButton) c;
		// btn.setMargin(new Insets(0,0,0,0));
		// Insets margins = btn.getInsets();
		// btn.setMargin(btn.getInsets());//new Insets(2, margins.top, 2,
		// margins.bottom));
		btn.setFont(new Font(Font.DIALOG, Font.PLAIN, 12));
		if (!(c instanceof XDMButton)) {
			c.setForeground(Color.WHITE);
			c.setBackground(StaticResource.btnBgColor);
			btn.setBorderPainted(false);
		}
	}
}
 
Example 5
Project: incubator-netbeans   File: TableUISupport.java   View Source Code Vote up 5 votes
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 6
Project: incubator-netbeans   File: MenuEditLayer.java   View Source Code Vote up 5 votes
void configureNewComponent(RADComponent item) {
    if(item != null) {
        JComponent c = (JComponent) formDesigner.getComponent(item);
        if(c != null) {
            c.setForeground(Color.LIGHT_GRAY);
        }
    }
}
 
Example 7
Project: incubator-netbeans   File: MenuEditLayer.java   View Source Code Vote up 5 votes
private void configureEditedComponent(JComponent c) {
    if(c == null) return;
    if(USE_NEW_ITEM_COLOR_SWITCHING) {
        if(c.getForeground() == Color.LIGHT_GRAY) {
            c.setForeground(getNormalForeground(c));
        }
    }
}
 
Example 8
Project: Equella   File: FlatterButtonUI.java   View Source Code Vote up 5 votes
@Override
public void keyReleased(KeyEvent e)
{
	int code = e.getKeyCode();
	if( code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE )
	{
		JComponent c = (JComponent) e.getComponent();
		c.setForeground(mTextNormal);
		c.setBackground(mBackgroundNormal);
	}
}
 
Example 9
Project: incubator-netbeans   File: ProfilerTreeTable.java   View Source Code Vote up 5 votes
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    setValue(value, row); // NOTE: should use table.convertRowIndexToModel(row)
    JComponent comp = getComponent();
    comp.setOpaque(false);
    if (tree != null) {
        comp.setForeground(tree.getForeground());
        comp.setBackground(tree.getBackground());
    }
    return comp;
}
 
Example 10
Project: Cognizant-Intelligent-Test-Scripter   File: StepRenderer.java   View Source Code Vote up 5 votes
@Override
public void render(JComponent comp, TestStep step, Object value) {
    comp.setForeground(getColor(step));
    if (step.isCommented() || step.hasBreakPoint()) {
        comp.setFont(new Font("Default", Font.BOLD, 11));
    }
}
 
Example 11
Project: rapidminer   File: OnboardingDialog.java   View Source Code Vote up 5 votes
private void decorateJComponent(JComponent component) {
    String prop = (String)component.getClientProperty("com.rapidminer.ui.label.type");
    if("header".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_28);
        component.setForeground(SwingTools.RAPIDMINER_ORANGE);
    } else if("bold".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_14);
        component.setForeground(Color.DARK_GRAY);
    } else if("normal".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_14);
        component.setForeground(Color.DARK_GRAY);
    } else if("large".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_16);
        component.setForeground(Color.DARK_GRAY);
    }

    prop = (String)component.getClientProperty("com.rapidminer.ui.button.type");
    if("cfa".equals(prop)) {
        component.setFont(OPEN_SANS_SEMIBOLD_14);
        component.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
    } else if("normal".equals(prop)) {
        component.setFont(OPEN_SANS_LIGHT_14);
        component.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        component.setMinimumSize(new Dimension(175, component.getPreferredSize().height));
        component.setPreferredSize(new Dimension(175, component.getPreferredSize().height));
    }

    prop = (String)component.getClientProperty("com.rapidmniner.ui.link_button.id");
    if(prop != null && component instanceof LinkButton) {
        ((LinkButton)component).setText(this.generateHTML(prop));
    }

    Color foregroundColor = (Color)component.getClientProperty("com.rapidminer.ui.label.foreground");
    if(foregroundColor != null) {
        component.setForeground(foregroundColor);
    }

}
 
Example 12
Project: Equella   File: FlatterCheckBoxUI.java   View Source Code Vote up 5 votes
@Override
public synchronized void mouseReleased(MouseEvent e)
{
	JComponent c = (JComponent) e.getComponent();
	c.setForeground(mTextNormal);
	c.setBackground(mBackgroundNormal);
	c.repaint();
}
 
Example 13
Project: Equella   File: FlatterCheckBoxUI.java   View Source Code Vote up 5 votes
@Override
public synchronized void mouseEntered(MouseEvent e)
{
	JComponent c = (JComponent) e.getComponent();
	if( c.isEnabled() )
	{
		c.setForeground(mTextActive);
		c.setBackground(mBackgroundActive);
		c.repaint();
	}
}
 
Example 14
Project: Equella   File: FlatterCheckBoxUI.java   View Source Code Vote up 5 votes
@Override
public synchronized void mouseExited(MouseEvent e)
{
	JComponent c = (JComponent) e.getComponent();
	c.setForeground(mTextNormal);
	c.setBackground(mBackgroundNormal);
	c.repaint();
}
 
Example 15
Project: Equella   File: FlatterCheckBoxUI.java   View Source Code Vote up 5 votes
@Override
public synchronized void keyReleased(KeyEvent e)
{
	int code = e.getKeyCode();
	if( code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE )
	{
		JComponent c = (JComponent) e.getComponent();
		c.setForeground(mTextNormal);
		c.setBackground(mBackgroundNormal);
	}
}
 
Example 16
Project: Equella   File: FlatterButtonUI.java   View Source Code Vote up 5 votes
@Override
public void keyPressed(KeyEvent e)
{
	int code = e.getKeyCode();
	if( code == KeyEvent.VK_ENTER || code == KeyEvent.VK_SPACE )
	{
		JComponent c = (JComponent) e.getComponent();
		c.setForeground(mTextPressed);
		c.setBackground(mBackgroundPressed);
	}
}
 
Example 17
Project: incubator-netbeans   File: Coloring.java   View Source Code Vote up 4 votes
/** 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
Project: incubator-netbeans   File: SheetTable.java   View Source Code Vote up 4 votes
/** Paint the expandable sets.  These are painted double width,
 *  across the entire width of the table. */
private void paintExpandableSets(Graphics g) {
    int start = 0;
    int end = getRowCount();

    Insets ins = getInsets();

    boolean canBeSelected = isKnownComponent(
            KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()
        );

    for (int i = 0; i < end; i++) {
        int idx = start + i;
        Object value = getValueAt(idx, 0);

        if (value instanceof PropertySet) {
            Rectangle r = getCellRect(idx, 0, false);
            r.x = ins.left;
            r.width = getWidth() - (ins.left + ins.right);

            if (g.hitClip(r.x, r.y, r.width, r.height)) {
                PropertySet ps = (PropertySet) value;

                String txt = ps.getHtmlDisplayName();
                boolean isHtml = txt != null;

                if (!isHtml) {
                    txt = ps.getDisplayName();
                }

                if (htmlrenderer == null) {
                    htmlrenderer = HtmlRenderer.createRenderer();
                }

                JComponent painter = (JComponent) htmlrenderer.getTableCellRendererComponent(
                        this, txt, false, false, idx, 0
                    );

                htmlrenderer.setHtml(isHtml);
                htmlrenderer.setParentFocused(true);

                htmlrenderer.setIconTextGap(2);

                htmlrenderer.setIcon(
                    getPropertySetModel().isExpanded(ps) ? PropUtils.getExpandedIcon() : PropUtils.getCollapsedIcon()
                );

                boolean selected = canBeSelected && (getSelectedRow() == idx);

                if (!selected) {
                    painter.setBackground(PropUtils.getSetRendererColor());
                    painter.setForeground(PropUtils.getSetForegroundColor());
                } else {
                    painter.setBackground(PropUtils.getSelectedSetRendererColor());
                    painter.setForeground(PropUtils.getSelectedSetForegroundColor());
                }

                if( PropUtils.isAqua ) {
                    painter.setOpaque(false);
                    Graphics2D g2d = (Graphics2D) g;
                    Paint oldPaint = g2d.getPaint();
                    g2d.setPaint( new GradientPaint(r.x,r.y, Color.white, r.x, r.y+r.height/2, painter.getBackground()) );
                    g2d.fillRect(r.x, r.y, r.width, r.height);
                    g2d.setPaint(oldPaint);
                } else {
                    painter.setOpaque(true);
                }

                paintComponent(g, painter, r.x, r.y, r.width, r.height);
            }
        }
    }
}
 
Example 19
Project: Cognizant-Intelligent-Test-Scripter   File: AbstractRenderer.java   View Source Code Vote up 4 votes
protected void setDefault(JComponent comp) {
    comp.setForeground(Color.BLACK);
    comp.setToolTipText(null);
}
 
Example 20
Project: AgentWorkbench   File: OntologyVisualisationConfiguration.java   View Source Code Vote up 4 votes
/**
 * Sets the color for a component that is located in a cell of a JTable.
 *
 * @param comp the JComponent
 * @param row the row
 * @param isSelected the is selected
 */
public static void setTableCellRendererColors(JComponent comp, int row, boolean isSelected) {

	// --- do the settings --------------
	comp.setOpaque(true);
	if (isSelected == true) {
		comp.setForeground(Colors.TB_TEXTFOREGROUND_SELECTED);
		comp.setBackground(Colors.TB_HIGHLIGHT);

	} else {
		comp.setForeground(Colors.TB_TEXTFOREGROUND);
		if (row%2==0) {
			comp.setBackground(Colors.TB_BACKGROUND);
		} else {
			comp.setBackground(Colors.TB_ALTERNATEROWCOLOR);			
		}
	}

	// --- In case of debugging ---------
	if (debug==false) {
		return;

	}
	if (colorPropertiesAlreadyPrinted==false) {
		List<String> colors = new ArrayList<String>();
		for (Map.Entry<Object, Object> entry : UIManager.getDefaults().entrySet()) {
			if (entry.getValue() instanceof Color) {
				colors.add((String) entry.getKey()); // all the keys are strings
			}
		}
		Collections.sort(colors);
		for (String name : colors) {
			System.out.println(name);
		}
		
		// --- Print the current color setting ----
		printColorSetting();

		colorPropertiesAlreadyPrinted = true;
	}

}