Search code examples
javaswingautomated-testsjemmy

How to get colour, font of java table row/cell/text with Jemmy?


Need to check colour/font style of java table (text, background) in swing application cause style of row should depend on a column value.

styled jTable

It is possible to get colour of font and background of selected (cell/row):

mainTable.selectCell(0, 0);
String bgcol = mainTable.getSelectionBackground().toString();  // => javax.swing.plaf.ColorUIResource[r=51,g=153,b=255]
String fgcol = mainTable.getSelectionForeground().toString();  // => javax.swing.plaf.ColorUIResource[r=255,g=255,b=255]    

But selected cell/row has its own style of selection, so this check becomes quite useless.

What is the way to accomplish style checking of any cell/row (not just selected) with Jemmy library?


Solution

  • A renderer is used to paint each cell in the table. You should be able to access the component used to render the cell with code something like:

    TableCellRenderer renderer = table.getCellRenderer(row, column);
    Component c = table.prepareRenderer(renderer, row, column);
    System.out.println(c.getBackground());