Swing provides cell editors for instances of JTable and JTree. For example, by default, JTable supports instances of JTextField, JComboBoxe and JCheckBox as cell editors, as the following figure illustrates:

FEST-Swing provides support for editing JTable cells (support for JTree coming soon) as if a user was doing it. To accomplish this, FEST-Swing uses custom cell writers (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 Writer |
Default Implementation |
Supported Cell Editor |
|---|---|---|---|
|
|||
Coming soon |
N/A |
N/A |
If your GUI has custom cell editors that FEST-Swing does not support by default, you can supply your own cell writer. You just need to implement the cell writer interface (see the table above) or extend any of the default implementations.
The following code listing shows how to provide a cell writer for a JTable that uses a JRadioButton as cell editor:
To use your custom cell reader, you just need to pass an instance of the cell reader to the appropriate fixture through the method cellWriter:
5 Comments
Hide/Show CommentsOct 12, 2009
Jean-Baptiste Perriot
Hello,
Two points for today :
1. BasicJTableCellWriter needs a constructor with a Robot. You have to reuse the robot of your main fixture (a Frame usually) : window.robot
in the setup :
in the test :
2. JTableFixture.enterValue can just take a String in parameter while a TableCellEditor, TableModel, TableCellRenderer use Objects.
The use of Objects enable the developper to use rich editors. It would be really useful to be able to do so with FEST.
Regards
Oct 14, 2009
Alex Ruiz
Hello Jean-Baptiste,
Another good catch! I apologize for the late reply. I got a little flu
I truly appreciate your help! and I'm impressed by your detailed observations!
Once again, many thanks!
Cheers!
Oct 15, 2009
Jean-Baptiste Perriot
Hello.
Hope you are fine now. :)
You are welcome for the help. I am studying the possibility to add IHM tests to one of my team projects and I think we are going to use FEST. I am currently making some tests in order to validate we can test everything we need to.
The main blocking point are the Tables but I found an [ugly] solution in order to tests the rich editors (string parsing :/). I will try to post something soon about a way to do it.
Regards.
Oct 15, 2009
Alex Ruiz
Thanks Jean-Baptiste, I'm back to normal
I agree about tables. They are pretty ugly, but that was the best solution I could think of at that time. I'm always open for new ways to improve the project. I'm looking forward for your feedback!
Cheers!
Oct 16, 2009
Jean-Baptiste Perriot
Hello,
If you talk about your fixtures for tables, they are not ugly. The fact you are using String is limiting but not blocking.
I will have a look in your code in details in order to see if I can change this to Objects, but for the moment I paused my work on FEST. I have got some enhancements and bugs fixing to do :-)