1

I'm currently working on a Netbeans Platform application that uses com.formdev.flatlaf.FlatLightLaf as the Look and Feel. The application is using Java 11 and running under Windows 10.

I would now like to change the color of the TitlePane. Changing the color of specific elements (like jPanels etc.) globally for the entire application can be done by changing properties within the UIManager. So I tried changing many of the background-color specific settings from UIManager.getDefaults() as well as UIManager.getLookAndFeelDefaults(). For example changing the TitlePane.background property to something like UIManager.put("TitlePane.background", new ColorUIResource(100, 100, 100));. However none of the dozens of properties I changed worked at all.

The color can be changed though as evidenced by the changed color of the TitlePane when using the com.formdev.flatlaf.FlatDarkLaf (darkmode).

If anyone has any idea which properties need to be changed in order to change the color of the title pane in a Netbeans Platform application I would very much appreciate any form of help!

Daki
  • 97
  • 9
  • [Read this SO thread](https://stackoverflow.com/questions/2482971/how-can-i-change-the-color-of-titlebar-in-jframe). – DevilsHnd - 退職した Aug 16 '21 at 09:09
  • Already did that. The accepted answer of "is not possible" is wrong. Setting `activeCaption` or `activeTitleBackground` did nothing for me. And I think it is redundant to code the access to the titelBar when the appropriate code ist already present and being used by LaFs included in Netbeans. So I figured this Problem is likely dependent on me using either Netbeans Platform and/or FlatLaF. – Daki Aug 16 '21 at 11:02
  • Have you checked the FlatLaf sources: https://github.com/JFormDesigner/FlatLaf/blob/main/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java ? – Joachim Rohde Aug 17 '21 at 07:48
  • You should have a look to the Netbeans source code as well (https://github.com/apache/netbeans/tree/12.4/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf), as FlatLaf is pre-integrated and I think Netbeans has its own specific settings. – jjazzboss Aug 17 '21 at 20:55
  • Thanks for both your hints! Within the FlatLaf sources the color of the titlePane ist set via "TitlePane.background". Sadly though this does not work here. I also checked the Netbeans (FlatLaF) code and in the class `FlatLFCustoms ` the method `updateUnifiedBackground` seems to do just that by checking "Panel.background" and setting that color for the unified background. Although this Options changes the appearance quite a lot overall (all jPanels background colors are affected) the TitleBar itself remains unchanged. – Daki Aug 19 '21 at 09:30
  • I found the solution. See my Answer – Arsh Coder Dec 05 '21 at 14:08

2 Answers2

2

I believe I found the culprit. In a recent release of Netbeans the option to set "TitlePane.unifiedBackground" for FlatLaF was introduced. However when setting UIManager.put("TitlePane.unifiedBackground", true); the problem described above will occur and I effectively can't set the background color of the TitlePane.

As seen in the method updateUnifiedBackground() of class FlatLFCustoms(https://github.com/apache/netbeans/blob/12.4/platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLFCustoms.java) in the Netbeans source code, the color of the titlePane should be set by adjusting the property "Panel.background". This however doesn't seem to work properly.

A workaround seems to be to set UIManager.put("TitlePane.unifiedBackground", false); and then just set the "TitlePane.background" to the desired color. If you still want the unified TitlePane look you can achieve that by also setting "Panel.background" and "Toolbar.background" to the same color.

In effect this will look identical to setting the unifiedBackground for the TitlePane only now you can change the color. Hope this helps someone who stumbles upon the same Problem.

Daki
  • 97
  • 9
0

Use this code:-

JFrame.setDefaultLookAndFeelDecorated(true);
frame.getRootPane().putClientProperty("JRootPane.titleBarBackground", new Color(23,180,252));
       frame.getRootPane().putClientProperty("JRootPane.titleBarForeground", Color.white);
Arsh Coder
  • 688
  • 9
  • 33
  • As far as I can see, this would require access to a jFrame instance. This however ist not given within Netbeans RCP, or at least this is not how one is supposed to handle the Netbeans platform. – Daki Dec 10 '21 at 15:10