-
June 5th, 2006, 06:40 PM
#1
Changing JPanel frame title bar background color
Is it possible to do something like this:
(if frame dont have focus) {
change title bar color
}
and a ActionListener that makes title bar color default when the frame gets focus
-
June 6th, 2006, 07:11 AM
#2
Re: Changing JPanel frame title bar background color
I take it you mean "Changing JFrame title bar" and not JPanel.
Prior to Java 1.4 the title bar was provided by the system, however, since 1.4 it can be provided by the LookAndFeel (if it supports frame decorations)by calling setDefaultLookAndFeelDecorated() on your JFrame instance.
This does mean you would have to write your own LookAndFeel If you want to take this on try reading:
http://java.sun.com/products/jlf/ed2/book/
Alternatively it may be possible to do it using the Synth look and feel but I've never used it in anger so can't help further on this.
I don't know of any other ways this can be done but hopefully someone else knows an easier way.
-
June 6th, 2006, 10:24 AM
#3
Re: Changing JPanel frame title bar background color
It is (would be) possible via the Synth framework, but although it allows you to define a Look & Feel using XML, which is far simpler than writing a traditional LAF, I believe there are no default Synth LAFs available yet - the examples I've found only define tiny subsets of a full LAF.
What would be nice is for Sun to supply all the standard LAFs using Synth, and provide a mechanism you to override or 'tweak' only the parts you want to change. As it is, you have to write a complete LAF just to make your title bar change color.
Programming is similar to a game of golf. The point is not getting the ball in the hole but how many strokes it takes...
H. Mills
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
June 7th, 2006, 08:10 AM
#4
Re: Changing JPanel frame title bar background color
FaithRaven:
You should be able to change the title bar colour if you use can use a JInternalFrame - you would of course still have to have a parent JFrame but you could make that undecorated (no title bar or borders). You would lose the min/max/close icons as JInternalFrame only has a minimise icon. It's a bit of a cludge but without knowing what your application is and why you need to change title bar colours I can't tell if it's remotely suitable.
I've dumped to screen the property keys registered with UIManager and there are keys for JIternalFrame titlebars.
InternalFrame.activeTitleBackground
InternalFrame.inactiveTitleBackground
InternalFrame.titleFont
You set the values you require as follows:
Code:
UIManager.put("InternalFrame.activeTitleBackground", Color.RED);
UIManager.put("InternalFrame.titleFont", new Font(fontName, Font.PLAIN, fontSize));
dlorde:
What would be nice is for Sun to supply all the standard LAFs using Synth
That would be great but I suspect that they would have done it by now if they were going to do it at all.
The following article suggests a reference implementation of synth LaF is being written but it's dated Sept 05 and I can't find any more recent references.
http://weblogs.java.net/blog/gfx/arc...week_cust.html
We could always just write one ourselves
-
June 7th, 2006, 12:41 PM
#5
Re: Changing JPanel frame title bar background color
Originally Posted by keang
We could always just write one ourselves
The novelty would wear off after a few minutes... this kind of boring translation is just what computers were made for - it should be possible to generate a Synth LAF from the older versions programmatically
The key to performance is elegance, not batallions of special cases...
J. Bently & D. McIlroy
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
June 8th, 2006, 12:39 PM
#6
Re: Changing JPanel frame title bar background color
The novelty would wear off after a few minutes
Don't worry it already has and I haven't done anything yet.
This kind of boring translation is just what computers were made for - it should be possible to generate a Synth LAF from the older versions programmatically
Now that would be cool - so can we look forward to you posting the generated LaF's then
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|