下面列出了java.awt.Container#getBackground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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 );
}
}
/**
* 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
}
/**
* 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;
}