Skip to end of metadata
Go to start of metadata

FEST-Swing provides support for editing JTable cells as if a user was doing it. Out of the box, JCheckBox, JComboBox and JTextField are supported as custom cell editors:

There are many ways to simulate a user editing a JTable cell:

JTableFixture

JTableFixture provides the method enterValue(TableCell, String) which simulates a user entering the given value in the given cell, regardless of the underlying cell editor. Even though the value to enter is always a String, JTableFixture can figure out how to use the underlying cell editor.

The following code listing illustrates how to select the value "Pool" from the JComboBox in row 0, column 2 (see picture above).

Here we are selecting the JCheckBox in row 1, column 4:

JTableCellFixture

JTableCellFixture provides the method enterValue(String), which can also simulate a user editing a table cell, just like JTableFixture.

The following code listing illustrates how to select the value "Pool" from the JComboBox in row 0, column 2:

Here we are selecting the JCheckBox in row 1, column 4:

Having more control of the cell editor

To have more control of the underlying cell editor, it is possible to wrap it with an implementation of ComponentFixture. JTableCellFixture provides the method editor(), which returns the Component used as editor of a cell. JTableCellFixture also provides the methods startEditing, stopEditing and cancelEditing. The following example illustrates how to use them:

Custom cell editors

FEST-Swing also supports custom cell editors. For more information, please read Custom Cell Editors.

4 Comments

  1. Do not know if it is an evolution or juste a mistake in the doc but it seems that you should use TableCell.row static function for retreiving a cell :

    replace :

    by :

  2. Thanks Jean-Baptiste! I wanted to keep the static imports (IMHO, the read better,) so I added comments specifying that row was statically imported. What do you think? (smile)

    Cheers!

  3. I am not a fan of static imports myself. Personal habit :)

    But at least it is now clear which is the only important thing here :)

  4. Alex,

    Is there anything I can do to improve the performance on the call to table.enterValue()? Everything speeds along nicely up to this point and then it takes forever to edit the cell.

    I'm using the 1.1 release so I don't know if this was something that was improved in your latest release.