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

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

源代码1 项目: FlatLaf   文件: FlatTaskPaneUI.java
@Override
protected void installDefaults() {
	if( group.getContentPane() instanceof JComponent ) {
		// remove default SwingX content border, which may be still set when switching LaF
		JComponent content = (JComponent) group.getContentPane();
		Border contentBorder = content.getBorder();
		if( contentBorder instanceof CompoundBorder &&
			((CompoundBorder)contentBorder).getOutsideBorder() instanceof BasicTaskPaneUI.ContentPaneBorder &&
			((CompoundBorder)contentBorder).getInsideBorder() instanceof EmptyBorder )
		{
			content.setBorder( null );
		}

		// set non-UIResource color to background to avoid that it is lost when switching LaF
		background = UIManager.getColor( "TaskPane.background" );
		Color bg = content.getBackground();
		if( bg == null || bg instanceof UIResource ) {
			content.setBackground( new Color( background.getRGB(), true ) );
		}
	}

	roundHeight = FlatUIUtils.getUIInt( "TaskPane.roundHeight", UIManager.getInt( "Component.arc" ) );

	super.installDefaults();
}
 
源代码2 项目: FlatLaf   文件: FlatRadioButtonUI.java
@Override
public void paint( Graphics g, JComponent c ) {
	// fill background even if not opaque if
	// - contentAreaFilled is true and
	// - if background was explicitly set to a non-UIResource color
	if( !c.isOpaque() &&
		((AbstractButton)c).isContentAreaFilled() &&
		!(c.getBackground() instanceof UIResource) )
	{
		g.setColor( c.getBackground() );
		g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
	}

	// small insets fix
	int focusWidth = getIconFocusWidth( c );
	if( focusWidth > 0 ) {
		boolean ltr = c.getComponentOrientation().isLeftToRight();
		Insets insets = c.getInsets( tempInsets );
		int leftOrRightInset = ltr ? insets.left : insets.right;
		if( focusWidth > leftOrRightInset ) {
			// The left (or right) inset is smaller than the focus width, which may be
			// the case if insets were explicitly reduced (e.g. with an EmptyBorder).
			// In this case the width has been increased in getPreferredSize() and
			// here it is necessary to fix icon and text painting location.
			int offset = focusWidth - leftOrRightInset;
			if( !ltr )
				offset = -offset;

			// move the graphics origin to the left (or right)
			g.translate( offset, 0 );
			super.paint( g, c );
			g.translate( -offset, 0 );
			return;
		}
	}

	super.paint( FlatLabelUI.createGraphicsHTMLTextYCorrection( g, c ), c );
}
 
源代码3 项目: FlatLaf   文件: FlatButtonUI.java
protected Color getBackgroundBase( JComponent c, boolean def ) {
	// use component background if explicitly set
	Color bg = c.getBackground();
	if( isCustomBackground( bg ) )
		return bg;

	return def ? defaultBackground : bg;
}
 
源代码4 项目: netbeans   文件: ViewUtil.java
/**
 * 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"));
    }
}
 
源代码5 项目: netbeans   文件: WinClassicViewTabDisplayerUI.java
/**
 * adds painting of overall border
 */
@Override
public void paint(Graphics g, JComponent c) {

    ColorUtil.setupAntialiasing(g);

    Color col = c.getBackground();
    if (col != null) {
        g.setColor (col);
        g.fillRect (0, 0, c.getWidth(), c.getHeight());
    }
    paintOverallBorder(g, c);
    super.paint(g, c);
}
 
源代码6 项目: pumpernickel   文件: LabelCellRenderer.java
protected void formatLabelColors(JComponent jc, boolean isSelected,
		int rowNumber) {
	if (comboBox != null) {
		if (isSelected) {
			label.setBackground(UIManager
					.getColor("ComboBox.selectionBackground"));
			label.setForeground(UIManager
					.getColor("ComboBox.selectionForeground"));
		} else {
			label.setBackground(UIManager.getColor("ComboBox.background"));
			label.setForeground(UIManager.getColor("ComboBox.foreground"));
		}
	} else {
		if (isSelected) {
			if (jc instanceof JList) {
				label.setBackground(UIManager
						.getColor("List.selectionBackground"));
				label.setForeground(UIManager
						.getColor("List.selectionForeground"));
			} else {
				label.setBackground(UIManager
						.getColor("Menu.selectionBackground"));
				label.setForeground(UIManager
						.getColor("Menu.selectionForeground"));
			}
		} else {
			Color background;
			if (jc != null) {
				background = jc.getBackground();
				if (rowNumber % 2 == 1 && isAlternatingBackround(jc)) {
					background = darken(background);
				}
			} else {
				background = UIManager.getColor("Menu.background");
			}
			label.setBackground(background);
			label.setForeground(UIManager.getColor("Menu.foreground"));
		}
	}
}
 
源代码7 项目: jdk1.8-source-analysis   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码8 项目: dragonwell8_jdk   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码9 项目: jdk8u60   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码10 项目: JDKSourceCode1.8   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码11 项目: openjdk-jdk8u   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码12 项目: openjdk-8-source   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码13 项目: 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);
                }
            }
        }
    }
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码15 项目: Bytecoder   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码16 项目: openjdk-jdk9   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码17 项目: openjdk-8   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码18 项目: jdk8u-dev-jdk   文件: LoweredBorder.java
@Override
protected Object[] getExtendedCacheKeys(JComponent c) {
    return (c != null)
            ? new Object[] { c.getBackground() }
            : null;
}
 
源代码19 项目: PolyGlot   文件: PGTUtil.java
/**
 * gets a worker that can make a given component flash
 *
 * @param flashMe component to make flash
 * @param flashColor color to use for flashing
 * @param isBack whether display color is background (rather than foreground)
 * @return SwingWorker that will make given component flash if run
 */
public static SwingWorker getFlashWorker(final JComponent flashMe, final Color flashColor, final boolean isBack) {
    // this will pop out in its own little thread...
    return new SwingWorker() {
        @Override
        protected Object doInBackground() {
            Color originColor;
            if (isBack) {
                originColor = flashMe.getBackground();
            } else {
                originColor = flashMe.getForeground();
            }

            Color requiredColor = flashColor.equals(originColor)
                    ? Color.white : flashColor;

            try {
                for (int i = 0; i < PGTUtil.NUM_MENU_FLASHES; i++) {
                    if (isBack) {
                        flashMe.setBackground(requiredColor);
                    } else {
                        flashMe.setEnabled(false);
                    }
                    // suppression for this is broken. Super annoying.
                    Thread.sleep(PGTUtil.MENU_FLASH_SLEEP);
                    if (isBack) {
                        flashMe.setBackground(originColor);
                    } else {
                        flashMe.setEnabled(true);
                    }
                    Thread.sleep(PGTUtil.MENU_FLASH_SLEEP);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                // catch of thread interrupt not logworthy
                // IOHandler.writeErrorLog(e);
            }

            return null;
        }
    };
}
 
源代码20 项目: material-ui-swing   文件: MaterialUIMovement.java
/**
 * Thie method create a new effect mouse hover static, not create a wake effect
 * This method is util in all component for click, an example: The button for JSpinner, JCombobox, JScroolbar
 * @param c is the component
 * @param colorEffect is the color for effect, (For using color, look the MaterialColors class)
 * @param colorOnClick is the color of the component on click on it
 * @return a new MaterialUIStaticMovement this class implement a only MouseListner for moment
 * @author https://github.com/vincenzopalazzo
 */
public static MaterialUIStaticMovement getStaticMovement(JComponent c, Color colorEffect, Color colorOnClick){
	if(c == null || colorEffect == null || colorOnClick == null){
		throw new IllegalArgumentException("Che input arguments is/are null");
	}
	return new MaterialUIStaticMovement(c.getBackground(), colorEffect, colorOnClick);
}