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

The following are Jave code examples for showing how to use setBackground() 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: 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 2
Project: incubator-netbeans   File: ViewUtil.java   View Source Code Vote up 5 votes
/**
 * Change background of given component to light gray on Mac look and feel
 * when the component is in a tabbed container and its background hasn't been
 * already changed (is instance of UIResource).
 * @param c
 */
static void adjustBackground( JComponent c ) {
    if( !isAquaLaF || useDefaultBackground )
        return;

    if( !isInTabbedContainer(c) )
        return;

    Color currentBackground = c.getBackground();
    if( currentBackground instanceof UIResource ) {
        c.setBackground(UIManager.getColor("NbExplorerView.background"));
    }
}
 
Example 3
Project: Cognizant-Intelligent-Test-Scripter   File: XTable.java   View Source Code Vote up 5 votes
private void setSelectionColor(Boolean rowSelected, Boolean cellSelected,
        JComponent comp, Color defalutRowBgColor) {
    if (rowSelected) {
        comp.setBackground(BG_SELECT_COLOR);
    } else {
        comp.setBackground(defalutRowBgColor);
    }
    if (cellSelected) {
        if (focused) {
            comp.setBackground(DEF_SELECTION_COLOR);
        } else {
            comp.setBackground(NOFOCUS_SELECTION_COLOR);
        }
    }
}
 
Example 4
Project: Wilmersdorf_SER316   File: TimeLogTableCellRenderer.java   View Source Code Vote up 5 votes
/**
 * Component showing task progress
 */

// some convenience methods
private void applySelectionStyle(boolean selected, JComponent c) {
    if (selected)
        c.setBackground(table.getSelectionBackground());
    else
        c.setBackground(table.getBackground());
}
 
Example 5
Project: incubator-netbeans   File: StatisticsPanel.java   View Source Code Vote up 5 votes
/**
 */
public StatisticsPanel(final ResultDisplayHandler displayHandler) {
    super(new BorderLayout(0, 0));
    this.displayHandler = displayHandler;
    JComponent toolbar = createToolbar();
    treePanel = new ResultPanelTree(displayHandler, this);
    treePanel.setFilterMask(filterMask);

    add(toolbar, BorderLayout.WEST);
    add(treePanel, BorderLayout.CENTER);
    if( isMacLaf ) {
        toolbar.setBackground(macBackground);
        treePanel.setBackground(macBackground);
    }
}
 
Example 6
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 7
Project: incubator-netbeans   File: IssuePanel.java   View Source Code Vote up 5 votes
private void updateFieldStatus(JComponent label, IssueField... fields) {
    label.setOpaque(false);
    for (IssueField field : fields) {
        boolean highlight = !issue.isNew() && (issue.getFieldStatus(field) & BugzillaIssue.FIELD_STATUS_MODIFIED) != 0;
        if (highlight) {
            label.setOpaque(true);
            label.setBackground(incomingChangesColor);
            break;
        }
    }
}
 
Example 8
Project: Equella   File: FlatterCheckBoxUI.java   View Source Code Vote up 5 votes
@Override
public synchronized 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 9
Project: rapidminer   File: DefaultPropertyKeyRenderer.java   View Source Code Vote up 5 votes
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean selected, int row, int column) {
	JComponent c = (JComponent) super.getTableCellEditorComponent(table, value, selected, row, column);
	if (!type.isOptional() && (type.getDefaultValue() == null)) {
		c.setFont(c.getFont().deriveFont(Font.BOLD, c.getFont().getSize()));
	}
	if (selected) {
		c.setBackground(SwingTools.LIGHTEST_BLUE);
	} else {
		c.setBackground(Color.WHITE);
	}
	return c;
}
 
Example 10
Project: Dahlem_SER316   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 5 votes
private void applySelectionStyle(boolean selected, JComponent c) {
    if (selected){
        c.setBackground(table.getSelectionBackground());
    }
    else
        c.setBackground(table.getBackground());
}
 
Example 11
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 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: Reinickendorf_SER316   File: SetAppDialog.java   View Source Code Vote up 5 votes
private void setJComponentBGandFG(JComponent jc) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException{
	jc.setBackground((Color)Color.class.getField(Configuration.get("BACKGROUND_COLOR_SETTING").toString()).get(null));
     try{
     	Color currnt = (Color)Color.class.getField(Configuration.get("BACKGROUND_COLOR_SETTING").toString()).get(null);
     	if(currnt.equals(Color.BLACK)){
     		jc.setForeground(Color.WHITE);
     	}
     	if(currnt.equals(Color.BLUE)){
     		jc.setForeground(Color.WHITE);
     	}
     }catch(IllegalArgumentException iae){
     	iae.printStackTrace();
     }
}
 
Example 14
Project: Neukoelln_SER316   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 4 votes
private void applySelectionStyle(boolean selected, JComponent c) {
    if (selected)
        c.setBackground(table.getSelectionBackground());
    else
        c.setBackground(table.getBackground());
}
 
Example 15
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 16
Project: openjdk-jdk10   File: TreePosTest.java   View Source Code Vote up 4 votes
/** Set the background on a component. */
private JComponent setBackground(JComponent comp, Color c) {
    comp.setOpaque(true);
    comp.setBackground(c);
    return comp;
}
 
Example 17
Project: AgentWorkbench   File: GraphGlobals.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(GraphGlobals.Colors.TB_TEXTFOREGROUND_SELECTED);
		comp.setBackground(GraphGlobals.Colors.TB_HIGHLIGHT);

	} else {
		comp.setForeground(GraphGlobals.Colors.TB_TEXTFOREGROUND);
		if (row%2==0) {
			comp.setBackground(GraphGlobals.Colors.TB_BACKGROUND);
		} else {
			comp.setBackground(GraphGlobals.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;
	}

}
 
Example 18
Project: Reinickendorf_SER316   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 4 votes
private void applySelectionStyle(boolean selected, JComponent c) {
    if (selected)
        c.setBackground(table.getSelectionBackground());
    else
        c.setBackground(table.getBackground());
}
 
Example 19
Project: SER316-Dresden   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 4 votes
private void applySelectionStyle(boolean selected, JComponent c) {
    if (selected)
        c.setBackground(table.getSelectionBackground());
    else
        c.setBackground(table.getBackground());
}
 
Example 20
Project: SER316-Aachen   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 4 votes
private void applySelectionStyle(boolean selected, JComponent c) {
    if (selected)
        c.setBackground(table.getSelectionBackground());
    else
        c.setBackground(table.getBackground());
}