Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing colour of panel title in Java Swing

I am running a Swing application on Win7 using a 144 dpi flatscreen monitor. The titles of my frames, option panes, etc., all appear in white on a transparent background (Aero?). I like Aero in general, but the white titles are very hard to read! I have gone through all the UIManager properties I can think of and none of them seem to have any effect. Is there a level below the UIManager that I can get to - and preferably make the change once off for my app, as I don't want to have to add code for every single option pane invocation. Maybe I am missing something very basic... but help would be appreciated!

I'd like to change the title fonts as well, but this is not as urgent!

Also, BTW, do you put UIManager.put calls before or after setting the Look and Feel? Or doesn't it matter?


More info: I changed over my Win7 personalization to use an Aero theme called Canada, and the titles are now in black, using a reasonable font. So my question becomes:

How do UIManager attributes relate to Win7 themes, and, given that I can't predict what theme users will be using, how do I control the pane title appearance?


I am going to put this question another way: why can't I change the colour of every pixel in my application's display panel? Is there a level below the UIManager, which seems to be very limited in what you are allowed to modify...?

like image 733
Paul Morrison Avatar asked Nov 27 '11 15:11

Paul Morrison


People also ask

How do I change the color of the title bar in Java Swing?

put("JFrame. activeTitleBackground", Color. red); for change the toolbar color in JFrame.

How do I change the color of a JPanel in Java?

We can set a background color to JPanel by using the setBackground() method.

How do I change the color of text in a JFrame?

setForeground(Color. X) ; will change the color of the text. For example, . setForeground(Color.

How do you change a title in Java?

First, you can set the JFrame title when you construct your JFrame, like this: JFrame jframe = new JFrame("My JFrame Title"); Second, once you have a valid JFrame object, you can call the setTitle method of the JFrame class, like this: jframe.


2 Answers

This way will be little bit complicated, but if you needed own Container with full-control,

1) create Un_decorated JFrame/JDialog

2) on the NORTH possition you can put JPanel with GradientPaint that simulating container that came from Win7

3) and put 3 JButtons with Icon to the JPanel with GradientPaint

4) add required events to the JButtons and for nicer output to the GUI would be to set JButtons#setContentAreaFilled(false)

like image 184
mKorbel Avatar answered Nov 04 '22 05:11

mKorbel


Use the setUndecorated(false) method to turn off the window decorations of the host platform.

Below is an example of this, though it is for the Mac OS platform, it may provide you with a starting point. Re-paint on translucent frame/panel/component.

like image 42
Andrew S Avatar answered Nov 04 '22 04:11

Andrew S