Java Code Examples for java.awt.Container#getBackground()

The following examples show how to use java.awt.Container#getBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlatRootPaneUI.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
protected void installDefaults( JRootPane c ) {
	super.installDefaults( c );

	// Update background color of JFrame or JDialog parent to avoid bad border
	// on HiDPI screens when switching from light to dark Laf.
	// The background of JFrame is initialized in JFrame.frameInit() and
	// the background of JDialog in JDialog.dialogInit(),
	// but it was not updated when switching Laf.
	Container parent = c.getParent();
	if( parent instanceof JFrame || parent instanceof JDialog ) {
		Color background = parent.getBackground();
		if( background == null || background instanceof UIResource )
			parent.setBackground( UIManager.getColor( "control" ) );
	}

	// enable dark window appearance on macOS when running in JetBrains Runtime
	if( SystemInfo.IS_JETBRAINS_JVM && SystemInfo.IS_MAC_OS_10_14_MOJAVE ) {
		LookAndFeel laf = UIManager.getLookAndFeel();
		boolean isDark = laf instanceof FlatLaf && ((FlatLaf)laf).isDark();
		c.putClientProperty( "jetbrains.awt.windowDarkAppearance", isDark );
	}
}
 
Example 2
Source File: FlatUIUtils.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the background color of the first opaque parent.
 */
public static Color getParentBackground( JComponent c ) {
	Container parent = findOpaqueParent( c );
	return (parent != null)
		? parent.getBackground()
		: UIManager.getColor( "Panel.background" ); // fallback, probably never used
}
 
Example 3
Source File: CodeFoldingSideBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves background color. Must be called after getColoring(), satisfied in updateColors.
 * @return 
 */
private Color resolveBackColor(boolean fallback) {
    AttributeSet attr = specificAttrs;
    Color x = (Color)attr.getAttribute(StyleConstants.ColorConstants.Background);
    if (x == null) {
        Container c = getParent();
        if (c != null) {
            x = c.getBackground();
        } else if (fallback) {
            // fallback in case of inherited color and uninitialized parent
            return getColoring().getBackColor();
        }
    }
    return x;
}