This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have some JComponents, mostly JTextFields, that I need to highlight when the user is in the field. I do this by changing the background to a color of their choosing. Problem comes in trying to set the background back to it's default when the user leaves that field. I started simply holding the original background in a variable and setting it back, but that's no good when the color it should be changes while it's highlighted (i.e. disabling changes the background color).
Isn't there some way to set a JTextField or JComponents in general back to their default background, whatever that should be at the current time? Or could I at least get the default background color from UIManager or some place and set it myself? I can't seem to find where the keys for UIManager are specified...
forgot to include the UIManager way tf.setBackground(UIManager.getColor("TextField.background"));
Joined: Jul 15, 2003
Thanks. I'm not sure what the program you provided is for, a brief glance looks like it shows different LAF, that doesn't really help me but thanks anyway. I knew I could use the UIManager that way, I just don't know where the valid keys are documented. I just ended up quickly printing them out to a console by getting the Enumeration. Now I can use TextField.background and TextField.disabledBackground.
I still want to know, however, if this is a good practice? Are those keys guaranteed to be there? What happens if they're not and I end up in a LAF or system where they don't return anything, I'm going to be stuck in the same position.
Joined: Jun 09, 2003
> I'm not sure what the program you provided is for it shows the UI default keys and their values (some with samples)
> Are those keys guaranteed to be there? I've seen too many things broken between 1.4 and 1.5 to have any certainty about anything working, as expected, in 1.6+
Joined: Jul 15, 2003
Great, so I'm in a lose/lose situation.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: How do I set the background to the default?