2

I want to implement this solution Display Modified JSlider Value Above Thumb.

But I do NOT want to use a MouseAdapter to control the Label (position and content). I just want the label to update when the value for the JSlider is modified. In my code I modify the value for the Jslider value in the paintComponent(Graphics g2) method. I dont know if this is the correct place to update the slider value using

slider.setValue (x) 

-- Edit:

I tried painting a rectangle but for some reason I cannot understand the position of the rectangle drawn and the slider pointer are not aligned.

    if (modified) {
        position += 55 - 2;
        modified=false;
    }

    g2.draw3DRect(position, slider.getY(), 150, 25, true);
    g2.setColor(Color.WHITE);
    g2.fill3DRect(position, slider.getY(), 150, 25, true);
    g2.setColor(Color.BLACK);

    if(startDate != null)
        g2.drawString(startDate.toString(), slider.getX(), slider.getY()); 

-- Edit:

I modified the code above and it looks like subtracting 2 from modified makes them more aligned

Community
  • 1
  • 1
MTA
  • 739
  • 2
  • 9
  • 29

0 Answers0