• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JSlider with moving Display Label with JSlider Label

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic