mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-14 07:47:12 -06:00
update JFrame/JDialog background color when switching Laf
This commit is contained in:
@@ -16,8 +16,15 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Container;
|
||||||
import javax.swing.JComponent;
|
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.ComponentUI;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicRootPaneUI;
|
import javax.swing.plaf.basic.BasicRootPaneUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,4 +42,21 @@ public class FlatRootPaneUI
|
|||||||
instance = new FlatRootPaneUI();
|
instance = new FlatRootPaneUI();
|
||||||
return instance;
|
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" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user