本文整理汇总了Java中javax.swing.JComponent.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.setBackground方法的具体用法?Java JComponent.setBackground怎么用?Java JComponent.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComponent
的用法示例。
在下文中一共展示了JComponent.setBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTableCellRendererComponent
import javax.swing.JComponent; //导入方法依赖的package包/类
@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;
}
示例2: adjustBackground
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* 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"));
}
}
示例3: setSelectionColor
import javax.swing.JComponent; //导入方法依赖的package包/类
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);
}
}
}
示例4: applySelectionStyle
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* 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());
}
示例5: StatisticsPanel
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
*/
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);
}
}
示例6: getTreeCellRendererComponent
import javax.swing.JComponent; //导入方法依赖的package包/类
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;
}
示例7: updateFieldStatus
import javax.swing.JComponent; //导入方法依赖的package包/类
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;
}
}
}
示例8: keyPressed
import javax.swing.JComponent; //导入方法依赖的package包/类
@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);
}
}
示例9: getTableCellEditorComponent
import javax.swing.JComponent; //导入方法依赖的package包/类
@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;
}
示例10: applySelectionStyle
import javax.swing.JComponent; //导入方法依赖的package包/类
private void applySelectionStyle(boolean selected, JComponent c) {
if (selected){
c.setBackground(table.getSelectionBackground());
}
else
c.setBackground(table.getBackground());
}
示例11: mouseExited
import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public synchronized void mouseExited(MouseEvent e)
{
JComponent c = (JComponent) e.getComponent();
c.setForeground(mTextNormal);
c.setBackground(mBackgroundNormal);
c.repaint();
}
示例12: mouseReleased
import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public synchronized void mouseReleased(MouseEvent e)
{
JComponent c = (JComponent) e.getComponent();
c.setForeground(mTextNormal);
c.setBackground(mBackgroundNormal);
c.repaint();
}
示例13: setJComponentBGandFG
import javax.swing.JComponent; //导入方法依赖的package包/类
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();
}
}
示例14: applySelectionStyle
import javax.swing.JComponent; //导入方法依赖的package包/类
private void applySelectionStyle(boolean selected, JComponent c) {
if (selected)
c.setBackground(table.getSelectionBackground());
else
c.setBackground(table.getBackground());
}
示例15: apply
import javax.swing.JComponent; //导入方法依赖的package包/类
/** 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);
}
}
}
}
}