Simple swing (UI L and F) problem

  • Follow


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....

0
Reply jkimble (57) 3/23/2005 8:41:57 PM

"James Kimble" <jkimble@one.net> wrote in message
news:1111610517.114872.128130@f14g2000cwb.googlegroups.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



0
Reply rhino1 (256) 3/23/2005 9:35:39 PM



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

0
Reply jkimble (57) 3/24/2005 2:10:47 PM

2 Replies
29 Views

(page loaded in 0.134 seconds)


Reply: