public int valueForYPosition(int yPos){
  int value;
  int minValue=slider.getMinimum();
  int maxValue=slider.getMaximum();
  int trackTop=trackRect.y + thumbRect.height / 2 + trackBorder;
  int trackBottom=trackRect.y + trackRect.height - thumbRect.height / 2 - trackBorder;
  int trackLength=trackBottom - trackTop;
  if (yPos <= trackTop) {
    value=drawInverted() ? minValue : maxValue;
  }
 else   if (yPos >= trackBottom) {
    value=drawInverted() ? maxValue : minValue;
  }
 else {
    int distanceFromTrackTop=yPos - trackTop;
    double valueRange=(double)maxValue - (double)minValue;
    double valuePerPixel=valueRange / (double)trackLength;
    int valueFromTrackTop=(int)Math.round(distanceFromTrackTop * valuePerPixel);
    value=drawInverted() ? minValue + valueFromTrackTop : maxValue - valueFromTrackTop;
  }
  return value;
}

public int valueForYPosition ( int yPos ) { int value ; int minValue = slider . getMinimum ( ) ; int maxValue = slider . getMaximum ( ) ; int trackTop = trackRect . y + thumbRect . height / 2 + trackBorder ; int trackBottom = trackRect . y + trackRect . height - thumbRect . height / 2 - trackBorder ; int trackLength = trackBottom - trackTop ; if ( yPos <= trackTop ) { value = drawInverted ( ) ? minValue : maxValue ; } else if ( yPos >= trackBottom ) { value = drawInverted ( ) ? maxValue : minValue ; } else { int distanceFromTrackTop = yPos - trackTop ; double valueRange = ( double ) maxValue - ( double ) minValue ; double valuePerPixel = valueRange / ( double ) trackLength ; int valueFromTrackTop = ( int ) Math . round ( distanceFromTrackTop * valuePerPixel ) ; value = drawInverted ( ) ? minValue + valueFromTrackTop : maxValue - valueFromTrackTop ; } return value ; }
returns a value give a y position . if ypos is past the track at the top or the bottom it will set the value to the min or max of the slider , depending if the slider is inverted or not .
