tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Open Symphony Core > Color to Hex Conversion

Color to Hex Conversion 

OSCore (Open Symphony Core) is a java library with lot of utilities and reusable components. This requires the libraries oscore-2.2.6.jar, mail.jar to be in classpath. The following example shows using TextUtils.colorToHex() API. It converts the given Color to Hex string.

File Name  :  
com/bethecoder/tutorials/oscore/Color2HexTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.oscore;

import java.awt.Color;

import com.opensymphony.util.TextUtils;

public class Color2HexTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    String colorHex = TextUtils.colorToHex(Color.BLUE);
    System.out.println(colorHex);
    
    colorHex = TextUtils.colorToHex(Color.GREEN);
    System.out.println(colorHex);
    
    colorHex = TextUtils.colorToHex(Color.GRAY);
    System.out.println(colorHex);
    
    colorHex = TextUtils.colorToHex(Color.ORANGE);
    System.out.println(colorHex);
  }

}
   

It gives the following output,
#0000ff
#00ff00
#808080
#ffc800



 
  


  
bl  br