YOUR FEEDBACK
NGASI Releases AppServer Manager 8.1
Dave Jenkins wrote: The remote server management is a welcomed added feature...


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


Using Color Technology in Java
Heighten the visual impact of your application

Digg This!

Brighten up your dreary application by learning how to use Java to create and manage color. Using a color picker makes it easy to define exact colors with alpha transparency.

For a developer there are two situations in which color comes up: when you are creating the colors for your interface and when a user can define colors or manipulate images as part of your application's functionality. To work with color effectively, you should know the basics of color management and color definition.

Color Management
Color technology comes in three main types: input devices (like scanners), display devices, and output devices (printers). The possible color range, called the "gamut," differs from device to device. Because of this the colors you see in an on-screen image will be different from those of a scanned or printed image. Controlling the color translation between different environments is what color management is all about.

You can do this translation using the Java 2D API's ColorSpace and ICC_Profile classes. First load the profiles for the two different environments. For the display you can use the built-in RGB profile that is the default. For a device like a scanner or printer, you'll usually need to load a color profile from a file from the manufacturer. For each of the profiles generate a ColorSpace object. ColorSpace has two methods: toCIEXYZ and fromCIEXYZ. The CIEXYZ color space is sort of a master color model that serves as the medium for translation. You can translate any color or image from one color space to another by translating it first to CIEXYZ, then to the target color space.

If you are programming for display only, that's about all you need to know about color management, but if you have color input/output in your application, you may want to learn more (see the resources section at the end of the article).

Picking Color
When users define a color, they need to have a dialog called a color picker. Unfortunately, the color picker that comes in the Swing package is somewhat inadequate. For one thing it has no support for alpha transparency. Also, it's hard to compare colors and see exact hues. Figure 1 shows a color picker that you can download from JDJ's Web site (www.sys-con.com/java/sourcec.cfm). This color picker allows your users (and you) to zero in on colors more easily and includes alpha transparency. Notice that the picker has two boxes: selected color versus compare color, which allow the user to compare two colors against each other. When the selection area is clicked, the compare and selection colors swap places. This is an efficient system for exploring and creating color.

 

An important consideration for color picking is that you should stick to the HSB (Hue, Saturation, Brightness) system rather than the monitor-oriented RGB encoding. It's much easier to define colors by starting with a hue and then modifying its brightness (shading) and saturation (tinting) than by trying to do an RGB mix. Table 1 shows the basic HSB combinations.

 

GUI Color Schemes
One way to increase the vitality of your application's interface is to create a logical color scheme. The problem with the typical battleship gray is low contrast, so in many cases there will be elements that are difficult for the user to read. Also it simply does not look that good; it's boring and monotonous. Many developers are leery of using colors because of the difficulty in finding a good matching set. You can overcome this problem by using the same combination books graphic designers use. I've listed such a swatch book in the resources section.

Even without using a swatch book there are some basic rules you can apply when creating a scheme. In general, it's best to use a two- or three-color scheme plus highlights. In a two-color scheme, it's a good idea to pick two complementary colors. In a three-color scheme start off with a triad (three hues spaced equally). To create highlights decrease the saturation of your base colors.

Other things to be aware of are the distance effect and contrast. When you look from afar, darker colors such as blue fade to black faster; red and blue are inherently darker than yellow and green. Maximizing contrast is a good policy but having black on white can be harsh. Using a pale yellow background may provide better readability. If you need large text to be read from a distance, for example, in a kiosk display, add a red one-pixel outline to the letters to increase contrast.

Resources

  • Fraser, B., Murphy, C., and Bunting, F. (2003). Real World Color Management. Peachpit Press.
  • Chijiiwa, H. (1987). Color Harmony. Rockport Publishers.
  • About John Chamberlain
    John Chamberlain is a developer in the Boston area who works at OPeNDAP.org. He holds a master's degree in computer science, is a frequent contributor to technical journals and has spoken at JavaOne. He can be reached by email at jdj@johnchamberlain or stop by his web site at http://johnchamberlain.com

    Malcolm wrote: The code supplied with the article is incorrect. However on http://johnchamberlain.co m the author has placed an updated version which does work.
    read & respond »
    Paul Pomeroy wrote: John, thanks for the short but good article on color. Regarding using a "swatch book" for finding compatible colors, your readers may want to look at ColorWrite (at www.adaptiveview.com/cw), a well regarded Java app. In addition to displaying more color combinations (all based on color theory) than you''ll ever find in a book, it generates Java (and HTML and CSS) code for using a selected color. It''s free, so help yourself. Paul Pomeroy ------------ www.adaptiveview.com
    read & respond »
    LATEST JAVA STORIES & POSTS
    Real-Time Kaazing Solution and Sun's Glassfish Forge RIA Alliance
    Kaazing Corporation and Sun Microsystems announced an alliance to deliver the scalable and advanced real-time Web 2.0 platform. The integration between Kaazing's real-time Rich Internet Application (RIA) solution, Enterprise Comet, and Sun Microsystems' open source Java EE applic
    Virtualization Journal Attracts JavaOne Attendees to SYS-CON Media Booth
    Virtualization Journal now reaches more than 60,000 online readers with monthly digital editions and weekly newsletters. The premier issue of the magazine's print edition, which debuts on May 6, 2008, at JavaOne in San Francisco, as a media sponsor of this event, will be availabl
    Sun Challenges Linux
    Sun's mule train has finally pulled into Indiana after three years on the road. Indiana is the Linux-friendly Fedora-like OpenSolaris project meant to move the Solaris-shy Linux community off Linux and on to Solaris tempted by Solaris widgetry like the highly scalable, rollback-e
    AJAX World - Sun Talks Up its Late-to-the-Party AIR-Silverlight Rival
    At Java One this week Sun has been selling its year -old-but-still-upcoming - and definitely late-to-the-party - Adobe AIR- and Microsoft Silverlight-competitive JavaFX Rich Client environment as a potential revenue-generator capable of putting ads on mobile applications and JavaF
    MySQL Backs Off Closed Source Plan
    MySQL has backed off a plan to charge for some encryption and compression backup widgetry in the next version of the database - and, heavens, NOT OPEN SOURCE THE STUFF, an idea it trotted a few weeks ago and predictably caught hell for. Sun, which bought MySQL for a billion dolla
    JavaOne Archives - Dvorak Comments on AMD Intel Lawsuit on SYS-CON.TV
    Conference in San Francisco. Dvorak held forth on a number of topics, including the new AMD/Intel lawsuit, the viability of Java and Sun, the value of (or lack thereof) of corporate PR, and whether or not a new book about Silicon Valley is really worth reading.
    SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
    SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

    SYS-CON FEATURED WHITEPAPERS

    ADS BY GOOGLE
    BREAKING JAVA NEWS
    Day Software to Present at Henry Stewart DAM Show
    Day Software (SWX:DAYN) (OTCQX:DYIHY), a leading provider of global content management