I have a long 2d string array, and I would like to sort by the 2nd value. It originates as:
public static final String names[][] = {
{"000000", "Black"},
{"000080", "Navy Blue"},
{"0000C8", "Dark Blue"},
{"0000FF", "Blue"},
{"000741", "Stratos"},
...
{"FFFFF0", "Ivory"},
{"FFFFFF", "White"}
};
As you can see, they are pre-sorted by the hex values. That is useful for part of the app.
There are 1,567 entries. I would like to alphabetize the color names and place them in a list widget. I need to keep the associated hex color values with the name values. All I can think of to do something like:
1) make a temporary long 1-d string array
2) fill it by loop that appends the hex values to the name values: temp[i] = new String (names
[1] + names[i][0])
3) sort temp[] with built in Java sort
4) make a permanent new string array, hexValues[] for the hex values
5) copy the last 6 characters of each item to hexValues[]
6) truncate the last 6 characters of each item in temp[]
7) build list widget with temp[]
Is there a more elegant way? What I'd really like to do is build a 1-d array of int's, with the values representing the alphabetized locations of the names. However, I don't see any built-in which would do that kind of indirect sort.
- - - - - - - - - -
Second question -- Can the backgrounds of each item in a list widget be a different color? Ideally the list would show the color name in black or white, and the its color value as background. Specifically, I'm trying to build the list accomplished by the Javascript code here:
* http://chir.ag/projects/name-that-color/
and add it to my Java interactive color wheel:
* http://r0k.us/graphics/SIHwheel.html
- - - - - - - - - -
BTW, I have converted his name that color Javascript (ntc.js) to a native Java class. It is freely distributable, and I host it here:
* http://r0k.us/source/ntc.java
-- Rich
Edited by: RichF on Oct 7, 2010 7:04 PM
Silly forum software; I can't see what made it go italic at the word new.