0
        } else { // outside of image or no raster set 
            bgColor = Color.WHITE;
            labelText = "";
        } 
 
        label.setBackground(bgColor);
        label.setForeground(findForegroundColor(bgColor));
        label.setText(labelText);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setVerticalAlignment(SwingConstants.CENTER);
        label.setFont(boldFont);
 
        return label;
    } 
 
    // From: http://www.w3.org/TR/AERT#color-contrast 
    // Two colors provide good color visibility if the brightness difference and the color difference between 
    // the two colors are greater than a set range. 
    // Color brightness is determined by the following formula: 
    // ((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000 
Contextual code suggestions in your IDE  Get Codota for Java