update JFrame/JDialog background color when switching Laf

This commit is contained in:
Karl Tauber
2020-06-02 15:46:36 +02:00
parent e0b0617ad2
commit c45a769aa3

View File

@@ -16,8 +16,15 @@
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicRootPaneUI;
/**
@@ -35,4 +42,21 @@ public class FlatRootPaneUI
instance = new FlatRootPaneUI();
return instance;
}
@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" ) );
}
}
}