This morning, i had spent a good part of my morning coffee trying to figured out how to put a custom color to my JInternalFrame title background. My client wanted to put a red color to indicate the frame associated with "Buy" business process and blue color to indicate the frame associated with "Sell". By default, i had wrote this code:
UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(Color.RED));
UIManager.put("InternalFrame.activeTitleForeground", new ColorUIResource(Color.WHITE));
UIManager.put("InternalFrame.titleFont", new Font("Dialog", Font.PLAIN, 11));
updateUI();
The code compiled fine and should have been worked fine. I had tested it using different component on the same frame, and they worked like a charm. However, in this JInternalFrame case, the only thing that worked was the titleFont which changed to small script quite different from the defaults. The color, was the same light blue as common to Metal Look and Feel - which i loved the most, by the way.
After mulling for about a couple of hours googling here and there, i found an explanation to this 'bug' here. Based on that article, i should able to overcome this problem if i used Windows Look and Feel. So, i added these lines of code prior to the lines above, and tested it:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}
When i executed it, i had this result:
which doesn't actually satisfy my needs. But something was right. The title foreground color was exactly what i had wanted. White. It led me to a simple conclusion, i changed my window theme to windows XP's Silver to Window Classic's and voila.
The color was exactly what i had wanted. But, my homework still remains that i had to be able to enforced the color i wanted regardless of the theme on the client's Operating System that runs my application.
Did you ever figure out how to change the background color on a JInternalFrame using different window themes (other than Windows Classic)? I am having the same problem
ReplyDeleteHi Rhama,
ReplyDeleteNice post. Thank you for sharing your knowledge with us.
I need to remove the JInternalFrame icon in order to prevent action menu when I click on the frame icon. Do you have any suggestions?