When filling a Totalcross Grid, I have conditional records that should be highlighted relative to the others. I thought about changing the color of the line, or showing the font in bold.
Grid by default shows "zebra" lines with white and gray colors interspersed and can be easily modified with the attributes firstStripeColor and secondStripeColor, in addition to the row when selected, with highlightColor. These alternatives do not serve me, because I can have records in sequence to be highlighted. I looked for a bit in the documentation and found the class totalcross.ui.Grid.CellController, this one might answer but I did not find any examples of how to use it.
Can the CellController be used for this, or is there any other alternative to just the Grid?
Implementation:
public class GridController extends CellController { int[] highlight; public GridController(int[] highlight) { this.highlight = highlight; } @Override public int getBackColor(int row, int col) { return (highlight[row] == 1) ? Color.RED : -1; } @Override public String[] getChoices(int arg0, int arg1) { return null; } @Override public int getForeColor(int arg0, int arg1) { return 0; } @Override public boolean isEnabled(int arg0, int arg1) { return true; } }
And to use, I create an array of integers with the size of the list, and inside the loop in the desired condition I assign the value 1 that will be the condition for the line to be detached, instantiate the GridController class created before and hedge in the grid:
private void buildGrid() { int highlight[] = new int[lista.size()]; for (int i = 0; i < lista.size(); i++) { X x = lista[i]; if (x.getOverdue().isAfter(x.getDueDate())) highlight[i] = 1; grid.add(new String[] { x.getId(), x.getDescricao() }); } GridController gridController = new GridController(highlight); grid.setCellController(gridController); repaint(); }