Working With SytemColor Class in Java

Introduction

 
In this article, we are going to explain that the SystemColor class provides a standard set of symbolic colours representing each distinct type of colour on the desktop. It is common for platform desktops (Windows 95, Solaris/CDE, etc.) to provide a colour scheme for objects on the desktop, and typically this scheme is configurable by the user. It is usually desirable to have applications running on that desktop use that colour scheme in order to maintain visual consistency.
There are the following symbolic colour objects created automatically and stored statically in java.awt.SystemColor.
  
Description of Some general Fields :
 
1-desktop 
This is the Background Color of your desktop.  
Syntax
public final static SystemColor desktop; 
 
2-activeCaption 
This is the colour of system caption.  
Syntax
public final static SystemColor activeCaption;
  
3-activeCaptionText 
This field returns the colour of the caption text.  
Syntax
public final static SystemColor activeCaptionText;
  
4-activeCaptionBorder
This fields returns the colour of caption borders. 
Syntax
public final static SystemColor activeCaptionBorer
 
5-menu 
This field returns the Background colour of the menus.  
Syntax
public final static SystemColor menu.
  
Remains Fields listed following: 
 
public final static SystemColor controlText;  
public final static SystemColor controlLtHighlight;  
public final static SystemColor controlHighlight;  
public final static SystemColor controlShadow;  
public final static SystemColor controlDkShadow;  
public final static SystemColor inactiveControlText;  
public final static SystemColor scrollbar;  
public final static SystemColor info;  
public final static SystemColor deskto;  
public final static SystemColor activeCaption;  
public final static SystemColor activeCaptionext;  
public final static SystemColor activeCaptionBorer;  
public final static SystemColor inactiveCaption;  
public final static SystemColor inactiveCaptionText;  
public final static SystemColor inactiveCaptionBorder;  
public final static SystemColor window;  
public final static SystemColor windowBorder;  
public final static SystemColor infoText;  
public final static SystemColor windowText;  
public final static SystemColor menu;  
public final static SystemColor menuext;  
public final static SystemColor text;  
public final static SystemColor textext;  
public final static SystemColor textHiglight; 
public final static SystemColor textHighlighText; 
public final static SystemColor control;
  
In the following example, we are going to show most of the colours we show by using the set background colour of the frame. And we use a colour array[] for storing colours which are obtained by the previous methods.
 
In this program, we want to try to show most of the colour's id shown by cmd.
 
Example
  1. import java.awt.*;  
  2. import java.awt.SystemColor;  
  3.    
  4. public class SystemColorDemo {  
  5.    
  6.       public static void main(String[] a) {  
  7.             Color[] sysColor = new Color[] {   
  8.                   SystemColor.activeCaption,  
  9.                   SystemColor.activeCaptionBorder, SystemColor.activeCaptionText,  
  10.                   SystemColor.control, SystemColor.controlDkShadow,  
  11.                   SystemColor.controlHighlight, SystemColor.controlLtHighlight,  
  12.                   SystemColor.controlShadow, SystemColor.controlText,  
  13.                   SystemColor.desktop, SystemColor.inactiveCaption,  
  14.                   SystemColor.inactiveCaptionBorder,  
  15.                   SystemColor.inactiveCaptionText, SystemColor.info,  
  16.                   SystemColor.infoText, SystemColor.menu, SystemColor.menuText,  
  17.                   SystemColor.scrollbar, SystemColor.text,  
  18.                   SystemColor.textHighlight, SystemColor.textHighlightText,  
  19.                   SystemColor.textInactiveText, SystemColor.textText,  
  20.                   SystemColor.window, SystemColor.windowBorder,  
  21.                   SystemColor.windowText };  
  22.    
  23.             for (Color c : sysColor) {  
  24.                   System.out.println(c);  
  25.                   Frame f = new Frame("colors");  
  26.                   f.setSize(200200);  
  27.                   f.setVisible(true);  
  28.                   f.setBackground(c);  
  29.             }  
  30.       }  
  31. }   
OUTPUT
 
This is the initial output of the cmd and it shows all the colours which are stored in the colour array by using its fields.
 
Clipboard03.jpg
 
These are various colours as backgrounds of the following frame used by the system; it's not all the colours of your system; it's just a Demo.
 
Clipboard02.jpg
 


Similar Articles