2

so I have a JSlider that has a custom synth look and feel, that looks like this (in xml):

<!-- Make and Bind a SliderTrack style -->
<style id="SliderTrackStyle">
   <opaque value="FALSE"/>
</style>

<bind style="SliderTrackStyle" type="region" key="sliderTrack" />

<!-- Make and Bind a Vertical Slider Thumb style -->
<style id="verticalSliderThumbStyle">

   <state>
      <imagePainter method="sliderThumbBackground" path="/resources/images/slider/SliderThumbVertical.png"
     sourceInsets="0 0 0 0"/>
   </state>

   <state value="PRESSED">
      <imagePainter method="sliderThumbBackground" path="/resources/images/slider/SliderThumbVerticalPressed.png"
     sourceInsets="0 0 0 0"/>
   </state>

</style>

<bind style="verticalSliderThumbStyle" type="name" key="VerticalSlider.*" />

Now, this works nicely, and the JSlider looks like it should. I'm then controlling the value of the slider programatically, using slider.setValue(); I can also fire the mouse listeners on the slider programatically, since it has some code that is executed right when the slider is clicked and when it's released. Again, this all works well. However, I can't seem to figure out how to tell the slider to look pressed when the value is changing. Is there a way to tell swing to make the slider look pressed even though it's not physically pressed (trigger the PRESSED state in the L&F)?

EDIT: I can make this work by using a DISABLED state, which has the same look as the pressed state. I can then disable the slider, move it around, and enable it again later. Obviously, that's a pretty hacky way to achieve the pressed look. Any other ideas would be appreciated.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
SuperTron
  • 4,203
  • 6
  • 35
  • 62
  • there must be mouse or key events – mKorbel Oct 10 '13 at 05:33
  • Well, when I set the slider for the first time, I loop through its mouse listeners and call the mousePressed method in each. Then the last time I move the slider I call the mouseReleased method in the same way. So I should be calling all of those, and it doesn't seem like they change the L&F at all. What sort of key events are you thinking? – SuperTron Oct 10 '13 at 07:27
  • please isn't there something like as events from ButtonModel armed, selected, pressed(as you already used) – mKorbel Oct 10 '13 at 07:54
  • there is a setState in a ButtonModel, but It doesn't look like it applys to sliders. – SuperTron Oct 11 '13 at 21:17

0 Answers0