// Use a bunch of Label objects arranged in a grid to display the colors.
this.setLayout(new GridLayout(0, 3, 5, 5));
for(int i = 0; i < colors.length; i++) {
// Create a label object to display a system color and its name
Label l = new Label(color_names[i], Label.CENTER);
this.add(l);
// compute a foreground color to contrast with the background
Color bg = colors[i], fg;
int r = bg.getRed(), g = bg.getGreen(), b = bg.getBlue();
int avg = (r + g + b) / 3;
if (avg > 128) fg = Color.black;
else fg = Color.white;
// And assign the colors.
l.setBackground(bg);
l.setForeground(fg);
}