Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.alt.net!news-in-01.newsfeed.easynews.com!easynews.com!easynews!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Bart Cremers" Subject: Re: JSlider Set knob Colo Message-ID: <1164368819.019130.301150@45g2000cws.googlegroups.com> X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui In-Reply-To: <1164298946.477882.169810@m7g2000cwm.googlegroups.com> References: <1164298946.477882.169810@m7g2000cwm.googlegroups.com> Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 54 Date: Wed, 27 Apr 2011 15:26:00 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303917960 96.60.20.240 (Wed, 27 Apr 2011 10:26:00 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:26:00 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:172 To: comp.lang.java.gui Leit=E3o wrote: > Hi, > > I would like to change the JSlider's knob color. I saw an example > on the web that used the BasicSliderUI to do that, but it doesn't work > well. When I use that it paints correctly the Slider but the rest of > the window components are not painted. > You can see the code I am using below: > > > > Please if anyone has an idea of what is the problem please let me > know...I am using java 1.5_07 > > Thanks in advance, > > Carlos Leitao Hi, I do not get the problem you've got. All components seem to paint correctly, so the problem you've got could be in another area of your code. Besides that, it's possible to change the color of the knob by simply overriding some UIDefaults values. You could do the following: java.util.List sliderGradient =3D Arrays.asList(new Object[] { new Float(.3f), new Float(.3f), new ColorUIResource(0xC8DDF2), new Color(0x1b, 0x70, 0xe1), new ColorUIResource( 0x2b, 0x80, 0xF1 ) }); UIManager.getDefaults().put("Slider.gradient", sliderGradient); UIManager.getDefaults().put("Slider.focusGradient", sliderGradient); This way you don't have to implement your own UI. Note that this will work for the MetalLookAndFeel. Other L&F's might require other settings to change it.=20 Regards, Bart --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24