File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JSlider with moving Display Label with JSlider Label Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JSlider with moving Display Label with JSlider Label" Watch "JSlider with moving Display Label with JSlider Label" New topic
Author

JSlider with moving Display Label with JSlider Label

Anurag Blore
Ranch Hand

Joined: Jan 15, 2003
Posts: 74
Hi,
i am trying to add a Label on top of JSlider Knob
to display some values in that Label as the Slider moves forward or back side the values displayed in label must change and Label has to move along with Knob of the JSlider.
i am capturing the values from a text field which can be change by user.
pls try to reply.
thanks
Anurag
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hello,
I would use CardLayout for changing the labels. I have made the experience, that this works better (and is less risky) than repainting the label yourself.
1.) create a CardLayout that contains every label as a component (see the Swing Tutorial on CardLayout). you can change the content of the CardLayout dynamically, or create a new one later on.
2.) attach the appropriate listener to the JSlider. this listener will call the show-method on the CardLayout to switch to the specific label. as you can switch to the next and to the previous component of a CardLayout (thus, they are ordered), this listener won't even have to bother whith the name of the cards. At least, that's what I'm thinking right now, without having implemented anything.
hope this did help you a bit
Chantal
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
to place the labels directly over the knob, I'd add some empty border of a width that depends on their index in the list of labels.
Chantal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSlider with moving Display Label with JSlider Label
 
Similar Threads
JSlider
use my own image on the knob of a jslider
changing the outfit of the setting knob ofJSliders???
jslider thumb movement on clicking the component
Displaying Value Label in JSlider