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


Groups > comp.lang.java.programmer > #24850 > unrolled thread

JSlider interactions

Started byFredK <fred.l.kleinschmidt@gmail.com>
First post2013-07-30 14:24 -0700
Last post2013-08-01 17:50 -0400
Articles 4 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  JSlider interactions FredK <fred.l.kleinschmidt@gmail.com> - 2013-07-30 14:24 -0700
    Re: JSlider interactions "John B. Matthews" <nospam@nospam.invalid> - 2013-07-30 21:57 -0400
      Re: JSlider interactions FredK <fred.l.kleinschmidt@gmail.com> - 2013-07-31 10:34 -0700
        Re: JSlider interactions "John B. Matthews" <nospam@nospam.invalid> - 2013-08-01 17:50 -0400

#24850 — JSlider interactions

FromFredK <fred.l.kleinschmidt@gmail.com>
Date2013-07-30 14:24 -0700
SubjectJSlider interactions
Message-ID<81940cb0-8687-40f5-8eda-68bf8c8ff935@googlegroups.com>
Is there a way to set the block increment for a JSlider ?
By this I mean the change in value that occurs when the user clicks between the current position and one of the ends (similar to the block or unit increment for a JScrollBar). I can't find anything to do this in JScrollBar or BoundedRangeModel.

Or is it a UI-specific amount (I am using Nimbus).

For an integer slider, I want to drag the knob to the approximate position, and then be able to click near it to move one integer at a time. It appears that the default amount is 10% of the range, so when the range is from 0 to 40, clicking in the "trough" area moves the value by 4.

-- 
Fred K

[toc] | [next] | [standalone]


#24851

From"John B. Matthews" <nospam@nospam.invalid>
Date2013-07-30 21:57 -0400
Message-ID<nospam-52F747.21570130072013@news.aioe.org>
In reply to#24850
In article <81940cb0-8687-40f5-8eda-68bf8c8ff935@googlegroups.com>,
 FredK <fred.l.kleinschmidt@gmail.com> wrote:

> Is there a way to set the block increment for a JSlider ? By this I 
> mean the change in value that occurs when the user clicks between the 
> current position and one of the ends (similar to the block or unit 
> increment for a JScrollBar). I can't find anything to do this in 
> JScrollBar or BoundedRangeModel.
> 
> Or is it a UI-specific amount (I am using Nimbus).
> 
> For an integer slider, I want to drag the knob to the approximate 
> position, and then be able to click near it to move one integer at a 
> time. It appears that the default amount is 10% of the range, so when 
> the range is from 0 to 40, clicking in the "trough" area moves the 
> value by 4.

This handled by an instance of BasicSliderUI.TrackListener, for which 
you'll need a custom UI delegate, as shown here,

<http://stackoverflow.com/a/518672/230513>

and in How to Write a Custom Swing Component:

<https://today.java.net/pub/a/today/2007/02/22/how-to-write-custom-swing-component.html>

Interestingly, BasicSliderUI.ScrollListener is public, apparently to 
work around an IE bug.

As an aside, the API for each says.

  Instantiate it only within subclasses of .

while the source says,

  Instantiate it only within subclasses of <Foo>.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#24858

FromFredK <fred.l.kleinschmidt@gmail.com>
Date2013-07-31 10:34 -0700
Message-ID<cb89e71e-9972-43e9-8ed0-53be5f18833b@googlegroups.com>
In reply to#24851
On Tuesday, July 30, 2013 6:57:01 PM UTC-7, John B. Matthews wrote:
> In article <81940cb0-8687-40f5-8eda-68bf8c8ff935@googlegroups.com>,
> 
>  FredK <fred.l.kleinschmidt@gmail.com> wrote:
> 
> 
> 
> > Is there a way to set the block increment for a JSlider ? By this I 
> 
> > mean the change in value that occurs when the user clicks between the 
> 
> > current position and one of the ends (similar to the block or unit 
> 
> > increment for a JScrollBar). I can't find anything to do this in 
> 
> > JScrollBar or BoundedRangeModel.
> 
> > 
> 
> > Or is it a UI-specific amount (I am using Nimbus).
> 
> > 
> 
> > For an integer slider, I want to drag the knob to the approximate 
> 
> > position, and then be able to click near it to move one integer at a 
> 
> > time. It appears that the default amount is 10% of the range, so when 
> 
> > the range is from 0 to 40, clicking in the "trough" area moves the 
> 
> > value by 4.
> 
> 
> 
> This handled by an instance of BasicSliderUI.TrackListener, for which 
> 
> you'll need a custom UI delegate, as shown here,
> 
> 
> 
> <http://stackoverflow.com/a/518672/230513>
> 
> 
> 
> and in How to Write a Custom Swing Component:
> 
> 
> 
> <https://today.java.net/pub/a/today/2007/02/22/how-to-write-custom-swing-component.html>
> 
> 
> 
> Interestingly, BasicSliderUI.ScrollListener is public, apparently to 
> 
> work around an IE bug.
> 
> 
> 
> As an aside, the API for each says.
> 
> 
> 
>   Instantiate it only within subclasses of .
> 
> 
> 
> while the source says,
> 
> 
> 
>   Instantiate it only within subclasses of <Foo>.
> 
> 

I tried:
      slider.setUI( new BasicSliderUI( slider ) {
         @Override
         protected void scrollDueToClickInTrack( int direction ) {
            int value = slider.getValue();
            value += direction;
            slider.setValue( value );
         }
      } );

which works, but gives me a Basic LAF. The rest of my app is using Nimbus.
I haven't been able to figure out how to find or use a Nimbus SliderUI.
When I call slider.getUI(), it returns an instance of javax.swing.plaf.synth.SynthSliderUI.
If I change BasicSliderUI in the above code with SynthSliderUI, I get
an error saying that that class is not visible.
(Using Java 1.6)
-- 
Fred K

[toc] | [prev] | [next] | [standalone]


#24876

From"John B. Matthews" <nospam@nospam.invalid>
Date2013-08-01 17:50 -0400
Message-ID<nospam-C53B5B.17504001082013@news.aioe.org>
In reply to#24858
In article <cb89e71e-9972-43e9-8ed0-53be5f18833b@googlegroups.com>,
 FredK <fred.l.kleinschmidt@gmail.com> wrote:

> On Tuesday, July 30, 2013 6:57:01 PM UTC-7, John B. Matthews wrote:
> > In article <81940cb0-8687-40f5-8eda-68bf8c8ff935@googlegroups.com>,
> > 
> >  FredK <fred.l.kleinschmidt@gmail.com> wrote:
> > 
> [...]
> 
> I tried:
>       slider.setUI( new BasicSliderUI( slider ) {
>          @Override
>          protected void scrollDueToClickInTrack( int direction ) {
>             int value = slider.getValue();
>             value += direction;
>             slider.setValue( value );
>          }
>       } );
> 
> which works, but gives me a Basic LAF. The rest of my app is using 
> Nimbus. I haven't been able to figure out how to find or use a Nimbus 
> SliderUI. When I call slider.getUI(), it returns an instance of 
> javax.swing.plaf.synth.SynthSliderUI. If I change BasicSliderUI in 
> the above code with SynthSliderUI, I get an error saying that that 
> class is not visible. (Using Java 1.6)

Interestingly, javax.swing.plaf.synth.SynthSliderUI has package-private 
access in OpenJDK 6:

<http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/javax/swing/plaf/synth/SynthSliderUI.java>

but public access in OpenJDK 7:

<http://download.java.net/jdk7/archive/b126/docs/api/javax/swing/plaf/synth/SynthSliderUI.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web