> Java > tutorials > javanotes > MakeColorPage
> Java > tutorials > javanotes > MakeColorPage
by ZweiBieren MakeColorPage Java coffee cup logo
Source Explorer
Java Notes

* This button downloads an installer jar. To install the app, put the jar in a folder and double-click it. Double click the application's icon to run it.

MakeColorPage is one of the PhysPics tools for choosing colors.

MakeColorPage implements various strategies for arranging colors in a 2-D display. You can generate a page according to one of the given algorithms or create your own.

This table illustrates various stages as I struggled to show colors in a 2-D image.

This first column is an old version that overlaid each color with its name and code. My first MakeColorPage organized all colors by PCA. Just a mishmash. Then I sorted the colors by hue and treated each row by PCA. Output below. Still poor. So I sorted by hue and then sorted within rows by various attributes. Even the best of these, below, below, was poor. Then I sorted all colors by gray scale. Overall pretty good, but closer inspection shows that colors are scattered all over. My last gasp was to sort by hues and then take blocks of five rows. in each block I sorted left to right by lightness and then top-to-bottom by saturation. Unsatisfactory.

After all the above I gave up and invent the scheme in pickcolor.

Defining your own list of colors

If you have your own list of colors, they need to be defined in a CSV (comma-separated-values) file like physpics.com/pictools/colorlist.csv. The first line is a list of the fields:


Subsequent lines each have five fields separated by commas, ala


where these are the fields

  • rgb - hash mark followed by six hexadecimal digits
  • name - non-ASCII characters must be written as entities, like "é"
  • variant - a single digit to distinguish from other colors of the same name (optional)
  • source - a name in parentheses, like "(CSS)" hinting at the origin of the name(optional)
  • link - link to a website defining the color (optional). Non-ASCII characters must be %-encoded.

Comment lines begin with "!" and may appear anywhere beyond the initial field name line.

To read a color csv file, I recommend org.apache.commons.csv., packages CSVParser, CSVFormat, and csv.CSVRecord. I read colorlist.csv with

CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader()
for (CSVRecord data : parser) {
    String rgb = data.get("RGB");
    String name = data.get("NAME");
    . . . 

Running MakeColorPage

To run MakeColorPage, download Examples & Sources and double click it. (You must have Java installed.) The installer will unwrap itself into its current directory. Therein double click the "JavaNotes.jar" icon. It will display a menu. Click "MakeColorPage". You will see two windows. In the "Generate Color Page" window, the top half are parameters. Click one of the bottom half buttons to generate a colors page.

The MakeColorPage window. Parameters are the top half; action buttons the bottom.
Feed back window

Coding your own color grid

Perhaps my discouraging comments have only left you more determined to arrange colors in 2-D. If so, you may be able to adapt MakeColorPage/PCASortColors. The most direct approach is code your sorter as a static method in PCAColorSorter and add a button in MakeColorPage. Follow the patterns already there. Pick an existing button and find each instance. Those are the places to add code for your new button.

A less direct approach is to instantiate a MakeColorPage object and call its methods. See the MakeColorPage javadoc. First read the colors from an InputStream:


Then follow the general pattern of handleButton:

void handleButton(String buttonName) {
    Bucket buck = new Bucket(buttonName, nColumns.getInt(), prepareColorList(buttonName));
    InputStream tplStream = getTplStream();   // where to read template
    if (tplStream == null) 

    // Compute O U T S T E M   
    //    String outputStemDefault = "colorrows";    
    //    JTextField outputStem = new JTextField(outputStemDefault);
    File outputFile 
            = new File("./"+outputStem.getText()+"-"+buttonName+".php");

    genPage(buck, outputFile, tplStream);
Copyright © 2023 ZweiBieren, All rights reserved. Feb 1, 2023 21:35 GMT Page maintained by ZweiBieren