Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #162

JSlider Set knob Color

From "Leitão" <¶ év‰ï@THRWHITE.remove-dii-this>
Subject JSlider Set knob Color
Message-ID <1164298946.477882.169810@m7g2000cwm.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:25 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
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:



slider= new JSlider(JSlider.VERTICAL);
slider.setUI(new coloredThumbSliderUI(slider,new
Color(0x1b,0x70,0xe1)));

	public class coloredThumbSliderUI extends BasicSliderUI{

	    Color thumbColor;
	    coloredThumbSliderUI(JSlider s, Color tColor) {
	        super(s);
	        thumbColor=tColor;
	    }

		public void paint( Graphics g, JComponent c ) {
	        recalculateIfInsetsChanged();
	        recalculateIfOrientationChanged();
	        Rectangle clip = g.getClipBounds();

	        if ( slider.getPaintTrack() && clip.intersects( trackRect ) )
{
	            paintTrack( g );
	        }
	        if ( slider.getPaintTicks() && clip.intersects( tickRect ) ) {
	            paintTicks( g );
	        }
	        if ( slider.getPaintLabels() && clip.intersects( labelRect ) )
{
	            paintLabels( g );
	        }
	        if ( slider.hasFocus() && clip.intersects( focusRect ) ) {
	            paintFocus( g );
	        }
	        if ( clip.intersects( thumbRect ) ) {
	            Color savedColor = slider.getBackground();
	            slider.setBackground(thumbColor);
	            paintThumb( g );
	            slider.setBackground(savedColor);
	        }
	    }
	}

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

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

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

JSlider Set knob Color "Leitão" <¶év‰ï@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
  Re: JSlider Set knob Colo "Bart Cremers" <bart.cremers@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
    Re: JSlider Set knob Colo "Leitão" <¶év‰ï@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
      Re: JSlider Set knob Colo "Michael Rauscher" <michael.rauscher@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000

csiph-web