Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Simple swing (UI L and F) problem

Reply
Thread Tools

Simple swing (UI L and F) problem

 
 
James Kimble
Guest
Posts: n/a
 
      03-23-2005

I've been given the task up updating the appearence (ie color
when selected or not) of some JToggleButtons on a fairly large
application and it seems like a really bad idea to do this via
btn.setBackground or btn.setForeground etc... I know it should be done
via a UIManager to uniformly set the look and feel of these buttons to
something different than the default. The problem I
have is that I have no idea how to do this and I haven't been
able to find anything useful on the internet.

The original author did some of this stuff but changing doesn't
seem to change the appearance of the app and I have to wonder if
it's doing anything at all.

---------------------------------------------------------------
UIDefaults def = UIManager.getDefaults();

Object buttonBorder =
new UIDefaults.ProxyLazyValue(
"javax.swing.plaf.basic.BasicBorders",
"getButtonBorder");

def.putDefaults(new Object[]
{
"Button.border", buttonBorder,
"ProgressBar.selectionForeground", Color.black,
"ProgressBar.selectionBackground", Color.black,
"Panel.background", Color.gray,
"Button.background", Color.gray,
"Label.background", Color.gray,
} );
------------------------------------------------------------

Can someone give me a hint or point me to a useful resource
for this type of thing. How hard can it possibly be?

Any help much appreciated....

 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      03-23-2005

"James Kimble" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> I've been given the task up updating the appearence (ie color
> when selected or not) of some JToggleButtons on a fairly large
> application and it seems like a really bad idea to do this via
> btn.setBackground or btn.setForeground etc... I know it should be done
> via a UIManager to uniformly set the look and feel of these buttons to
> something different than the default. The problem I
> have is that I have no idea how to do this and I haven't been
> able to find anything useful on the internet.
>
> The original author did some of this stuff but changing doesn't
> seem to change the appearance of the app and I have to wonder if
> it's doing anything at all.
>
> ---------------------------------------------------------------
> UIDefaults def = UIManager.getDefaults();
>
> Object buttonBorder =
> new UIDefaults.ProxyLazyValue(
> "javax.swing.plaf.basic.BasicBorders",
> "getButtonBorder");
>
> def.putDefaults(new Object[]
> {
> "Button.border", buttonBorder,
> "ProgressBar.selectionForeground", Color.black,
> "ProgressBar.selectionBackground", Color.black,
> "Panel.background", Color.gray,
> "Button.background", Color.gray,
> "Label.background", Color.gray,
> } );
> ------------------------------------------------------------
>
> Can someone give me a hint or point me to a useful resource
> for this type of thing. How hard can it possibly be?
>
> Any help much appreciated....
>

I chose to do a similar thing in one of my applets a while back. This is a
fragment of my code which involves overriding the default attributes in the
UIManager; this code works fine:

/*
* Set the colour of the selected tab in the tabbed pane. Set the
colour
* of scrollbars. See
src/java/swing/plaf/basic/BasicLookAndFeel.java in
* src.jar for definitions of many of the default colours used in
Java.
*/
UIManager.put("TabbedPane.selected", SELECTED_TAB_COLOUR);
//ScrollBar.thumb -> knob
UIManager.put("ScrollBar.thumb", SCROLLBAR_KNOB_COLOUR);
//ScrollBar.background -> track
UIManager.put("ScrollBar.background", SCROLLBAR_TRACK_COLOUR);
//ScrollBar.thumbHighlight -> dimples on knob
UIManager.put("ScrollBar.thumbHighlight",
SCROLLBAR_KNOB_HIGHLIGHT_COLOUR);
//control -> default colour for controls (buttons, sliders, etc.)
UIManager.put("control", CONTROL_BACKGROUND_COLOUR);

By the way, SELECTED_TAB_COLOUR and the other all-capitalized variable names
all originate in an interface I built to store the colours which are
supposed to be used in the GUI. You could imitate that technique or replace
them with constants like Color.black, as in your example.

Rhino



 
Reply With Quote
 
 
 
 
James Kimble
Guest
Posts: n/a
 
      03-24-2005


I ended up writing some code to print out the contents the UIDefaults
table (it's a HashTable) and then just setting the relevant item
to the value I wanted. Man, this should not have taken this long...

Thanks for your suggestion.

jk



> I chose to do a similar thing in one of my applets a while back. This

is a
> fragment of my code which involves overriding the default attributes

in the
> UIManager; this code works fine:
>
> /*
> * Set the colour of the selected tab in the tabbed pane. Set

the
> colour
> * of scrollbars. See
> src/java/swing/plaf/basic/BasicLookAndFeel.java in
> * src.jar for definitions of many of the default colours

used in
> Java.
> */
> UIManager.put("TabbedPane.selected", SELECTED_TAB_COLOUR);
> //ScrollBar.thumb -> knob
> UIManager.put("ScrollBar.thumb", SCROLLBAR_KNOB_COLOUR);
> //ScrollBar.background -> track
> UIManager.put("ScrollBar.background",

SCROLLBAR_TRACK_COLOUR);
> //ScrollBar.thumbHighlight -> dimples on knob
> UIManager.put("ScrollBar.thumbHighlight",
> SCROLLBAR_KNOB_HIGHLIGHT_COLOUR);
> //control -> default colour for controls (buttons, sliders,

etc.)
> UIManager.put("control", CONTROL_BACKGROUND_COLOUR);
>
> By the way, SELECTED_TAB_COLOUR and the other all-capitalized

variable names
> all originate in an interface I built to store the colours which are
> supposed to be used in the GUI. You could imitate that technique or

replace
> them with constants like Color.black, as in your example.
>
> Rhino


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing is dead! Long live Swing. Knute Johnson Java 32 02-29-2012 05:10 PM
Why not using javax.swing.event with swing? S.T Java 2 05-25-2007 12:10 AM
javax.swing.Popup, javax.swing.PopupFactory lizard Java 0 01-30-2006 09:34 PM
Swing Model Classes Updating Swing Components on a Thread Other Than AWT mkrause Java 0 05-06-2005 04:32 PM
Java 1.2 Swing vs. Java 1.5 Swing Big Daddy Java 2 04-16-2005 01:14 PM



Advertisments