private int findClosestTick(int value)
int findClosestTick(int value)
  private int findClosestTick(int value)  {    int min = slider.getMinimum();    int max = slider.getMaximum();    int majorSpace = slider.getMajorTickSpacing();    int minorSpace = slider.getMinorTickSpacing();    // The default value to return is value + minor or    // value + major.     // Initializing at min - value leaves us with a default    // return value of min, which always has tick marks    // (if ticks are painted).    int minor = min - value;    int major = min - value;    // If there are no major tick marks or minor tick marks     // e.g. snap is set to true but no ticks are set, then    // we can just return the value.    if (majorSpace <= 0 && minorSpace <= 0)      return value;    // First check the major ticks.    if (majorSpace > 0)      {	int lowerBound = (value - min) / majorSpace;	int majLower = majorSpace * lowerBound + min;	int majHigher = majorSpace * (lowerBound + 1) + min;	if (majHigher <= max && majHigher - value <= value - majLower)	  major = majHigher - value;	else	  major = majLower - value;      }    if (minorSpace > 0)      {	int lowerBound = value / minorSpace;	int minLower = minorSpace * lowerBound;	int minHigher = minorSpace * (lowerBound + 1);	if (minHigher <= max && minHigher - value <= value - minLower)	  minor = minHigher - value;	else	  minor = minLower - value;      }    // Give preference to minor ticks    if (Math.abs(minor) > Math.abs(major))      return value + major;    else      return value + minor;  }