public static Color correctReadability(Color foreground,Color background){
  int bd=getBrightnessDifference(foreground,background);
  if (Math.abs(bd) < 50) {
    if (getBrightness(background) > 180) {
      foreground=makeDarker(foreground,0.5f);
    }
 else {
      foreground=makeBrighter(foreground,0.5f);
    }
  }
  return foreground;
}

public static Color correctReadability ( Color foreground , Color background ) { int bd = getBrightnessDifference ( foreground , background ) ; if ( Math . abs ( bd ) < 50 ) { if ( getBrightness ( background ) > 180 ) { foreground = makeDarker ( foreground , 0.5f ) ; } else { foreground = makeBrighter ( foreground , 0.5f ) ; } } return foreground ; }
tries to change the color ( if necessary ) so it it better readable on the given background color . this works for a few colors , but is far from perfect . for example some colors have a high enough brightness difference , but they are still not very well readable , e . g . springgreen on light grey .
