Changes in runtime.
Hello folks,
i want to change certain values after runtime. Before my JFrame is visible all changes are fine, but after setVisible(true) nothing happens. Is there a way to change certain values like...
UIManager.put("RootPane.background", Color.red);
UIManager.put("TitlePane.background", Color.red);
UIManager.put("TitlePane.inactiveBackground", Color.red);
... after initialisation? I saw the wonder first in the demo. What am i missing?
i Just found https://github.com/JFormDesigner/FlatLaf/issues/847. Am i right there? In my case i use JOGL for most of the Window and your FlatLightLaf serves as titleBar manipulation.
Sincerly & Thx
The values in UIManager are used when creating components and are then stored in component UI delegates. So you need to update UI delegates in that case.
You can use FlatLaf.updateUI() to update all UI delegates in your app.
Or SwingUtilities.updateComponentTreeUI( w ); to update a single window.
Thank you so much, Karl. I'll wrote a small demo for that. What didn't work for me so far is to change the RootPane.background. probably i am missing a certain keyword. the titlebar should be RED.
package examples;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
import javax.swing.*;
import java.awt.*;
public class Example_FlatLightLaf_Change {
private final JFrame frame;
public static void main(String[] args) {
new Example_FlatLightLaf_Change();
}
public Example_FlatLightLaf_Change() {
try {
UIManager.setLookAndFeel(new FlatLightLaf());
} catch (Exception ex) {
System.err.println("Failed to initialize LaF");
}
UIManager.put("flatlaf.useWindowDecorations", true);
UIManager.put("RootPane.background", Color.BLACK);
frame = new JFrame("FlatLAF Change Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(640, 480);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
change_theme();
}
public void change_theme() {
// ???
UIManager.put("RootPane.background", Color.RED);
FlatLaf.updateUI();
SwingUtilities.updateComponentTreeUI( this.frame);
}
}
I found it via Bing Copilot.
JRootPane rootPane = frame.getRootPane();
rootPane.putClientProperty("JRootPane.titleBarBackground", Color.RED);
Hooray :)