Java tutorial
//package com.java2s; import java.awt.Color; import java.awt.Toolkit; import javax.swing.JList; import javax.swing.UIManager; public class Main { private static Color selectionForegroundColor; /** * Get the foreground color for the current UI. * @return The desired foreground color. */ public static Color getSelectionForegroundColor() { if (selectionForegroundColor != null) { return selectionForegroundColor; } //for windows selectionForegroundColor = (Color) Toolkit.getDefaultToolkit() .getDesktopProperty("win.item.highlightTextColor"); if (selectionForegroundColor == null) { selectionForegroundColor = UIManager.getColor("Table.selectionForeground"); if (selectionForegroundColor == null) { selectionForegroundColor = UIManager.getColor("Table[Enabled+Selected].textForeground"); if (selectionForegroundColor == null) { selectionForegroundColor = new JList().getSelectionForeground(); } } //sometimes the UIManager color won't work selectionForegroundColor = new Color(selectionForegroundColor.getRed(), selectionForegroundColor.getGreen(), selectionForegroundColor.getBlue()); } return selectionForegroundColor; } }