本文整理汇总了Java中java.awt.Component.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java Component.setBackground方法的具体用法?Java Component.setBackground怎么用?Java Component.setBackground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.setBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFilechooserCard
import java.awt.Component; //导入方法依赖的package包/类
private JPanel createFilechooserCard() {
JPanel filechooserPanel = new JPanel(new BorderLayout());
filechooserPanel.setBackground(GettingStartedDialog.BACKGROUND_COLOR);
filechooserPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0));
filechooserPanel.add(new CardHeaderPanel("getting_started.header.location"), "North");
this.chooser = new RepositoryLocationChooser(this.owner, (RepositoryLocation)null, (String)null);
this.chooser.setBackground(GettingStartedDialog.BACKGROUND_COLOR);
this.chooser.setBorder(BorderFactory.createEmptyBorder(5, 20, 0, 20));
Component[] buttonPanel = this.chooser.getComponents();
int var3 = buttonPanel.length;
for(int var4 = 0; var4 < var3; ++var4) {
Component component = buttonPanel[var4];
component.setBackground(GettingStartedDialog.BACKGROUND_COLOR);
}
filechooserPanel.add(this.chooser, "Center");
JPanel var6 = new JPanel(new FlowLayout(2));
var6.setBackground(GettingStartedDialog.BACKGROUND_COLOR);
var6.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
var6.add(this.createSelectButton(this.chooser));
var6.add(this.createBackButton());
filechooserPanel.add(var6, "South");
return filechooserPanel;
}
示例2: prepareRenderer
import java.awt.Component; //导入方法依赖的package包/类
@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;
}
示例3: prepareRenderer
import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
boolean selected = false;
for(int i: getSelectedRows()) {
if(row == i) {
selected = true;
break;
}
}
Component c = super.prepareRenderer(renderer, row, column);
if(selected) {
c.setBackground(getSelectionBackground());
} else {
c.setBackground(backgroundColorForRow(row));
}
return c;
}
示例4: get
import java.awt.Component; //导入方法依赖的package包/类
private Component get(ClassNode value, boolean selected) {
Component result = new JLabel(value.toString());
if (selected) {
result.setBackground(Color.blue);
result.setForeground(Color.white);
JPanel resPane = new JPanel();
resPane.setLayout(new BorderLayout());
resPane.add(result, BorderLayout.CENTER);
return resPane;
} else {
return result;
}
}
示例5: getObject
import java.awt.Component; //导入方法依赖的package包/类
@Override
protected Component getObject() {
Component component = new MyComponent();
component.setBackground(Color.WHITE);
component.setFont(new Font(null, Font.BOLD, 5));
return component;
}
示例6: main
import java.awt.Component; //导入方法依赖的package包/类
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);
}
}
示例7: prepareEditor
import java.awt.Component; //导入方法依赖的package包/类
/** Overridden to set the colors apropriately - we always want the editor
* to appear selected */
@Override
public Component prepareEditor(TableCellEditor editor, int row, int col) {
if (editor == null) {
return null;
}
Component result = super.prepareEditor(editor, row, col);
if (result == null) {
return null;
}
if( 1 == col ) {
//Usually result == ine, but custom impls may not be
InplaceEditor ine = getEditor().getInplaceEditor();
if (ine.supportsTextEntry()) {
result.setBackground(PropUtils.getTextFieldBackground());
result.setForeground(PropUtils.getTextFieldForeground());
}
}
if (result instanceof JComponent) {
//unlikely that it won't be
((JComponent) result).setBorder(BorderFactory.createEmptyBorder(0, PropUtils.getTextMargin(), 0, 0));
}
return result;
}
示例8: getTableCellRendererComponent
import java.awt.Component; //导入方法依赖的package包/类
/**
* Returns the component used for drawing the cell. This method is
* used to configure the renderer appropriately before drawing.
*
* @param table the <code>JTable</code> that is asking the
* renderer to draw; can be <code>null</code>
* @param value the value of the cell to be rendered. It is
* up to the specific renderer to interpret
* and draw the value. For example, if
* <code>value</code>
* is the string "true", it could be rendered as a
* string or it could be rendered as a check
* box that is checked. <code>null</code> is a
* valid value
* @param isSelected true if the cell is to be rendered with the
* selection highlighted; false otherwise
* @param hasFocus if true, render cell appropriately. For
* example, put a special border on the cell, if
* the cell can be edited, render in the color used
* to indicate editing
* @param row the row index of the cell being drawn. When
* drawing the header, the value of
* <code>row</code> is -1
* @param column the column index of the cell being drawn
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component renderer;
renderer = getDrawComponent(value);
if (table.isCellEditable(row, column)) {
// If the cell is editable, returns a comboBox
combo.removeAllItems();
if (value != null) {
combo.addItem(renderer);
combo.setSelectedItem(value);
}
if (!isSelected) {
combo.setBackground(table.getBackground());
combo.setForeground(table.getForeground());
} else {
combo.setBackground(table.getSelectionBackground());
combo.setForeground(table.getSelectionForeground());
}
return combo;
} else {
// Otherwise returns the label only.
if (!isSelected) {
renderer.setBackground(table.getBackground());
renderer.setForeground(table.getForeground());
} else {
renderer.setBackground(table.getSelectionBackground());
renderer.setForeground(table.getSelectionForeground());
}
return renderer;
}
}
示例9: getTableCellRendererComponent
import java.awt.Component; //导入方法依赖的package包/类
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
{
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
Object valueAt = table.getModel().getValueAt(row, col);
String s = "";
if (valueAt != null)
{
s = valueAt.toString();
}
// if (s.contains("0"))
if (isSelected)
{
c.setForeground(GUISettings.itemSelectedForegroundColor);
c.setBackground(GUISettings.itemSelectedBackgroundColor);
if (!itemEdited.contains(row))
itemEdited.add(row);
} else
{
if (itemEdited.contains(row))
{
c.setForeground(GUISettings.itemEditedForegroundColor);
c.setBackground(GUISettings.itemEditedBackgroundColor);
}
else
{
c.setForeground(Color.black);
c.setBackground(Color.white);
}
}
return c;
}
示例10: getListCellRendererComponent
import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
Component listCellRendererComponent = super.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
if (LOADING.equals(value) || EMPTY.equals(value)) {
listCellRendererComponent.setBackground(list.getBackground());
listCellRendererComponent.setForeground(UIManager.getColor("Label.disabledForeground"));
listCellRendererComponent.setEnabled(false);
super.setText(LOADING == value ? LOADING_STRING : EMPTY_STRING);
}
return listCellRendererComponent;
}
示例11: setColor
import java.awt.Component; //导入方法依赖的package包/类
public void setColor() {
Color c = Color.LIGHT_GRAY;
this.setBackground(c);
for (Component comp : this.getComponents())
if (!(comp instanceof JButton))
comp.setBackground(c);
}
示例12: prepareEditor
import java.awt.Component; //导入方法依赖的package包/类
public Component prepareEditor(TableCellEditor editor, int row, int column) {
Component c = super.prepareEditor(editor, row, column);
c.setForeground(getSelectionForeground());
c.setBackground(getSelectionBackground());
return c;
}
示例13: getTreeCellRendererComponent
import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Color background = null;
if (value instanceof TreeNode) {
try {
java.lang.reflect.Field fnode = value.getClass().getDeclaredField("node");
fnode.setAccessible(true);
value = fnode.get(value);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
if (value instanceof Node) {
Node node = (Node) value;
DVThread thread;
do {
thread = node.getLookup().lookup(DVThread.class);
if (thread == null) {
node = node.getParentNode();
}
} while (thread == null && node != null);
if (thread != null) {
DVThread currentThread = getCurrentThread();
boolean isHighlighted = focusedThread != null && thread == focusedThread && node == value;
boolean isCurrent = currentThread == thread;
if (isHighlighted || isCurrent) {
background = isHighlighted ? highlightColor : currentThreadColor;
}
}
}
Component component = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (background != null) {
component.setBackground(background);
if (component instanceof JComponent) {
((JComponent) component).setOpaque(true);
}
}
return component;
}
示例14: render
import java.awt.Component; //导入方法依赖的package包/类
public void render(Graphics g, Font defaultFont,
Color defaultColor, Color backgroundColor,
int width, int height, boolean selected) {
Component renderComponent = getPaintComponent(selected);
renderComponent.setFont(defaultFont);
renderComponent.setForeground(defaultColor);
renderComponent.setBackground(backgroundColor);
renderComponent.setBounds(0, 0, width, height);
XMLCompletionResultItemPaintComponent xmlComp = (XMLCompletionResultItemPaintComponent)renderComponent;
// already set in getPaintComponent, but someone might override the getter, without an icon.
xmlComp.setIcon(icon);
xmlComp.paintComponent(g);
}
示例15: getTableCellRendererComponent
import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (!checkData(value, row, column)) {
c.setBackground(java.awt.Color.red);
} else {
c.setBackground(java.awt.Color.white);
}
return c;
}