🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #7743

Re: Customized slider knob imagery

#7743
From: Torsten Welches
Date: Sat, 06 Jan 2001 10:51
48 lines
2288 bytes
Lars,

JSlider uses a swing.plaf.SliderUI subclass to render the component.
SliderUI itself is an empty abstract class, but the basic non-abstract child
class BasicSliderUI has a public method paintThumb(Graphics g) that you
could override.

Because of the pluggable L&F feature there is more than one "real" SliderUI
(Metal, Windows ...), all of which inherit from BasicSliderUI. That makes is
more complicated (you have to register your SliderUI with the UIManager and
so on)

Here's an "non-production-quality" example that draws the thumb as a red
cycle:

class MySliderUI extends javax.swing.plaf.basic.BasicSliderUI {
    public MySliderUI(JSlider s) {
      super(s);
    }
    public void paintThumb(Graphics g) {
      g.setColor(Color.red);
      g.fillOval(thumbRect.x,  thumbRect.y, thumbRect.width,
thumbRect.height);
    }
    protected Dimension getThumbSize() {
      return new Dimension(15, 15);
    }
  }

Use it like that:

Slider slider = new JSlider();
slider.setUI(new MySliderUI(slider));

Viel Gl�ck,
Torsten

Lars Thuring schrieb in Nachricht <3A567ADC.25868A32@t-online.de>...
>Hi list,
>
>is there some convenient way of having your own images painted instead
>of the standard JSlider knobs? Or is the proper way overiding
>paintComponent(), finding out where the knob is and paint your image on
>top of it?
>
>Thanks in advance.
>
>Lars
Technical Details
Message-ID: <3a56f931$1_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!212.43.194.69!fr.clara.net!heighliner.fr.clara.net!news.imp.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!194.8.195.251
References: <3A567ADC.25868A32@t-online.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 111d45,f6e07f74041fb29d
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2001-01-06 03:00:23 PST
From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Newsgroups: borland.public.jbuilder.java.swing
References: <3A567ADC.25868A32@t-online.de>
Subject: Re: Customized slider knob imagery
Date: Sat, 6 Jan 2001 11:51:10 +0100
Lines: 50
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: 194.8.195.251
Message-ID: <3a56f931$1_1@dnews>
X-Trace: 6 Jan 2001 02:53:37 -0800, 194.8.195.251
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!212.43.194.69!fr.clara.net!heighliner.fr.clara.net!news.imp.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!194.8.195.251