下面列出了怎么用java.awt.SystemColor的API类实例代码及写法,或者点击链接到github查看源代码。
private void setIOColors() {
if (IOColors.isSupported(io) && IOColorPrint.isSupported(io)) {
Color colorStd = IOColors.getColor(io, IOColors.OutputType.OUTPUT);
//Color colorErr = IOColors.getColor(io, IOColors.OutputType.ERROR);
Color background = UIManager.getDefaults().getColor("nb.output.background"); // NOI18N
if (background == null) {
background = SystemColor.window;
}
colorStdBrighter = shiftTowards(colorStd, background);
//colorErrBrighter = shiftTowards(colorErr, background);
Color foreground = UIManager.getDefaults().getColor("nb.output.foreground"); // NOI18N
if (foreground == null) {
foreground = SystemColor.textText;
}
IOColors.setColor(io, IOColors.OutputType.INPUT, shiftTowards(foreground, Color.GREEN));
}
}
@Override
public Component getListCellRendererComponent (
JList<? extends ColorValue>
list,
ColorValue value,
int index,
boolean isSelected,
boolean cellHasFocus
) {
this.value = value;
setEnabled (list.isEnabled ());
setBackground (isSelected ?
SystemColor.textHighlight : SystemColor.text
//Color.RED
);
setForeground (isSelected ?
SystemColor.textHighlightText : SystemColor.textText
);
return this;
}
@Override
public Component getListCellRendererComponent(JList list,
Object soundObject, int row, boolean isSelected,
boolean hasFocus) {
label.setText(getSoundName(soundObject));
if (isSelected) {
label.setOpaque(true);
label.setBackground(SystemColor.textHighlight);
label.setForeground(SystemColor.textHighlightText);
} else {
label.setOpaque(list.isOpaque());
label.setBackground(SystemColor.text);
label.setForeground(SystemColor.textText);
}
return label;
}
public ColoredProgressBar(int start, int end) {
setMinimum(start);
setMaximum(end);
setForeground(SystemColor.window);
setBackground(SystemColor.window);
setBorder(new EmptyBorder(3, 5, 3, 5));
Dimension size = new Dimension(300, 20);
setPreferredSize(size);
setMaximumSize(size);
setMinimumSize(size);
BasicProgressBarUI ui = new BasicProgressBarUI() {
@Override
protected Color getSelectionForeground() {
return Color.BLACK;
}
@Override
protected Color getSelectionBackground() {
return Color.BLACK;
}
};
setUI(ui);
}
public JTree createJTree() {
setCurrentTree(new JTree(getTreeModel()));
currentTree.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof Editor) {
Icon icon = ((Editor) value).getIcon(leaf, expanded);
if (icon != null)
setIcon(icon);
if (clip == value && clipCutted) {
setForeground(SystemColor.textInactiveText);
}
}
return this;
}
});
return currentTree;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
public void setItem(Object anObject) {
value = anObject;
if (value instanceof String) {
setText(NbBundle.getMessage(SplashUISupport.class, "SplashUISupport_color_default"));
super.setForeground(SystemColor.textText);
super.setBackground(SystemColor.text);
} else {
setText("");
super.setBackground((Color) value);
}
}
public void setProfilingPointFactory(ProfilingPointFactory ppFactory, int index) {
this.ppFactory = ppFactory;
if (ppFactory != null) {
label.setText(ppFactory.getType());
label.setIcon(ppFactory.getIcon());
} else {
label.setText(NO_ACTION_NAME);
label.setIcon(NO_ACTION_ICON);
}
Component selected = null;
if ((index >= 0) && (index < previewPanel.getComponentCount())) {
selected = previewPanel.getComponent(index);
}
for (Component c : previewPanel.getComponents()) {
if (c == selected) {
Border empt1 = BorderFactory.createEmptyBorder(2, 2, 2, 2);
Border sel = BorderFactory.createMatteBorder(1, 1, 1, 1, SystemColor.textHighlight);
Border empt2 = BorderFactory.createEmptyBorder(0, 2, 0, 2);
Border comp1 = BorderFactory.createCompoundBorder(empt2, sel);
Border comp2 = BorderFactory.createCompoundBorder(comp1, empt1);
((JComponent) c).setBorder(comp2);
} else {
((JComponent) c).setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
}
}
}
@Override
public JToolTip createToolTip() {
JToolTip tooltp = new JToolTip();
tooltp.setBackground(SystemColor.control);
tooltp.setFont(getFont());
tooltp.setOpaque(true);
tooltp.setComponent(this);
tooltp.setBorder(null);
return tooltp;
}
@Override
public Component getEditorComponent () {
setEnabled (comboBox.isEnabled ());
setBackground (comboBox.isFocusOwner () ?
SystemColor.textHighlight : SystemColor.text
);
setForeground (comboBox.isFocusOwner () ?
SystemColor.textHighlightText : SystemColor.textText
);
return this;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
protected static Panel createBorderPanel(Component center) {
Panel p = new Panel();
p.setBackground(SystemColor.control);
p.setLayout(new BorderLayout());
p.add("Center", center);
p.add("North", createLabel(""));
p.add("South", createLabel(""));
p.add("East", createLabel(""));
p.add("West", createLabel(""));
p.setBackground(SystemColor.control);
return p;
}
/**
* Method declaration
*
*
* @param center
*/
private Panel createBorderPanel(Component center) {
Panel p = new Panel();
p.setBackground(SystemColor.control);
p.setLayout(new BorderLayout());
p.add("Center", center);
p.add("South", createLabel(""));
p.add("East", createLabel(""));
p.add("West", createLabel(""));
p.setBackground(SystemColor.control);
return p;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
LWTextComponentPeer(final T target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
getTarget().setBackground(SystemColor.text);
}
}
/**
* Returns an array of Colors similar to getGUIcolors(), but using the
* System colors. This is useful if pieces of a Component (such as
* the integrated scrollbars of a List) should retain the System color
* instead of the background color set by Component.setBackground().
*/
static Color[] getSystemColors() {
if (systemColors == null) {
systemColors = new Color[4];
systemColors[BACKGROUND_COLOR] = SystemColor.window;
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
}
return systemColors;
}
public StatusBar() {
setLayout( new BorderLayout() );
setPreferredSize( new Dimension( 10, 23 ) );
final JPanel rightPanel = new JPanel( new BorderLayout() );
rightPanel.add( new JLabel( new AngledLinesWindowsCornerIcon() ), BorderLayout.SOUTH );
rightPanel.setOpaque( false );
text = new JLabel();
add( text, BorderLayout.WEST );
add( rightPanel, BorderLayout.EAST );
setBackground( SystemColor.control );
}