By default, Swing displays values in instances of JComboBoxe, JList, JTable and JTree. Values are usually displayed using instances of JLabel. Developers can also define their own custom drawing options for those components by providing custom "cell renderers."

The following image shows a JTable using a JComboBox and a JCheckBox as custom renderers for columns 1 and 2 respectively:

FEST-Swing provides support for reading and verifying values (and selected values) from any GUI component that displays something meaningful to the users. FEST-Swing does not obtain those values from the model. Instead, it reads the values as they are displayed on the GUI, as if an actual user were reading them. To do so, FEST-Swing uses custom cell readers (in the package org.fest.swing.cell.)

The following chart shows the fixtures that support custom cell renderers (click on any cell to see Javadoc):

Fixture

Cell Reader

Default Implementation

Supported Cell Renderer

JComboBoxFixture

JComboBoxCellReader

BasicJComboBoxCellReader

JLabel

JListFixture

JListCellReader

BasicJListCellReader

JLabel

JTableFixture

JTableCellReader

BasicJTableCellReader

JLabel, JComboBox, JCheckBox

JTreeFixture

JTreeCellReader

BasicJTreeCellReader

JLabel

The following code listing show how to verify the values in our sample JTable using the BasicJTableCellReader that comes by default in a JTableFixture:

JTableFixture table = dialog.table("data");
table.requireContents(
  new String[][] {
      { "0-0", "first", "false" },  
      { "1-0", "first", "false" }, 
      { "2-0", "first", "false" }
  }
);

If your GUI has custom cell renderers that FEST-Swing does not support by default, you can supply your own cell reader. You just need to implement the cell reader interface (see the table above) or extend any of the default implementations.

The following code listing shows how to provide a cell reader for a JTable that uses a JRadioButton as cell renderer:

public class MyJTableCellReader extends BasicJTableCellReader {

  @Override public String valueAt(JTable table, int row, int column) {
    Component c = super.cellRendererComponent(table, row, column);
    if (c instanceof JRadioButton) 
      return String.valueOf(((JRadioButton)c).isSelected());
    return super.valueAt(table, row, column);
  }
}

To use your custom cell reader, you just need to pass an instance of the cell reader to the appropriate fixture through the method cellReader:

JTableFixture table = dialog.table("data");
table.cellReader(new MyJTableCellReader());