Here's some very old code that is an alternative, but probably not better, approach to Jim's:
NamesDefaultToHere(1);
//**********************************************************************************
// Function to build a display box containing colours and legends
//**********************************************************************************
colorKeyDB =
Function( {colorList, legendList},
{Default Local},
db = Panel Box( "Row State Colors" );
For( i = 1, i <= N Items( colorList ), i++,
tb = Text Box( "███" ||" "||legendList );
tb << fontcolor( RGB Color( Color To RGB( colorList ) ) );
db << Append( tb );
);
db;
);
// Data Table with row state colours
dt1 = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
col = Column(dt1, "lot_id");
dt1 << colorByColumn(col);
// Use an invisible summary table to get unique values (row state colours are carried over)
dt2 = dt1 << Summary( Group( col ), Invisible );
// Get the lists for the function "colorKeyDB"
cList = {};
lList = {};
For(r=1, r<=NRow(dt2), r++,
Row() = r;
colorCode = Color Of( Row State( Row() ) );
Insert Into( cList, colorCode );
Insert Into( lList, Char( Column( dt2, "lot_id" )[Row()] ) );
);
Close(dt2, NoSave);
// Put the legend in a window
nw = New Window( "Colour Legend", HListBox(colorKeyDB(cList, lList ), ButtonBox("OK", nw << closeWindow)) );