JXtension - Color.getSafeColor()

Purpose:
Give the user the ability to determine what the color of the text should be if background is set to a specific color.

Returns:
Returns either black or white depending on the luminance of the color.  White will be returned if the luminance is less than 128.  Black will be returned if the luminance is greater than or equal to 128.

Example #1:
The following will instantiate a color using three random numbers.  After that, the background of the textbox will be set to the constructed color.  Finally, the color of the text will be set to an easy to read color based on that of the background:

 

See also: