Change from DefaultGenericTable to results table


I am trying to modify the pendant drop plug in so that it uses the results table instead of a deafult generic table.

I have changed the code from:

results = new DefaultGenericTable(colCount, stack.getSize());
        results.setColumnHeader(0, "slice");
        results.setColumnHeader(1, "tip radius");
        results.setColumnHeader(2, "tip x");
        results.setColumnHeader(3, "tip y");
        results.setColumnHeader(4, "gravity angle");
        results.setColumnHeader(5, "capillary length");
        results.setColumnHeader(6, "surface tension");
        results.setColumnHeader(7, "volume");
        results.setColumnHeader(8, "surface");
        results.setColumnHeader(9, "RMS fit distance (pixels)");

            results.set(0, n, n+1);
            results.set(1, n, drop.getTipRadius());
            results.set(2, n, drop.getTipX());
            results.set(3, n, drop.getTipY());
            results.set(4, n, drop.getGravityAngle());
            final double capLength = drop.getCapillaryLength();
            results.set(5, n, capLength);
            final double surface_tension = capLength * capLength * rho_g;
            results.set(6, n, surface_tension);
            results.set(7, n, dropFit.getVolume());
            results.set(8, n, dropFit.getSurface());
            results.set(9, n, Math.sqrt(dropFit.getFitDistance()));


            import ij.measure.ResultsTable;
            results_table.addValue("slice", n);
            results_table.addValue("tip radius", drop.getTipRadius());
            results_table.addValue("tip x", drop.getTipX());
            results_table.addValue("tip y", drop.getTipY());
            results_table.addValue("gravity angle", drop.getGravityAngle());
            final double capLength = drop.getCapillaryLength();
            results_table.addValue("capillary length", capLength);
            final double surface_tension = capLength * capLength * rho_g;
            results_table.addValue("surface tension", surface_tension);
            results_table.addValue("surface", dropFit.getSurface());
            results_table.addValue("RMS fit distance (pixels)", Math.sqrt(dropFit.getFitDistance()));

however, I get this error when I run the plugin in ImageJ

[ERROR] Module threw exception
java.lang.IllegalArgumentException: Counter==0
	at ij.measure.ResultsTable.addValue(

My aim is to change the code so that I can use a macro or change the plug in so I can export the results to excel.

Just so people are aware - you posted this on stack overflow too right?


Hey @Nima_Hojat,

I did this conversion in a course some years ago as exercise. Here comes the solution:

Let us know if this helps!



Yes I did. I wasn’t sure which site was more appropriate.
Kind regards,

Thank you Robert,
I will try it and get back to you all.

1 Like

As @haesleinhuepf implicitly pointed out by linking to the complete solution, you’re missing a call to the incrementCounter() method, as the Counter==0 error tries to suggest.

May I ask why you feel the need to use the ij.ResultsTable class? The org.scijava.table.DefaultGenericTable class is supposed to be the ImageJ2 equivalent of ResultsTable, providing full ‘headless’ compatibility while being more generic than its predecessor. I acknowledge that there were problems with this table implementation in Fiji/ImageJ2 in the past (e.g. you couldn’t save tables from the UI, but that’s now possible using File>Export>Table…).

If you tell us what issues you had with DefaultGenericTable (either in this forum topic, or by submitting a new issue on GitHub), maybe we can go forward as a community and solve it for the benefit of all IJ2-style plugins that make use of SciJava tables.

(Disclaimer: I am a contributor to the scijava-table repository :slight_smile:)


@Nima_Hojat, @imagejan:
Add “results_table.incrementCounter()” to avoid the “counter==0” error. This example

   rt = new ResultsTable();
   // add values to first row
   rt.addValue("slice", 11);           
   rt.addValue("tip radius", 12);
   rt.addValue("tip x", 13);
   // add values to second row
   rt.addValue("slice", 21);           
   rt.addValue("tip radius", 22);
   rt.addValue("tip x", 23);"Results");

creates a two row table:

     slice  tip radius  tip x
  1    11      12        13
  2    21      22        23

With the latest ImageJ daily build (1.53f21), rt.addValue() automatically increments the counter if it is zero, so you no longer need to call incrementCounter() to create a one row table.



Thank you for your reply. When I run the plugin with the DefaultGenericTable I do not get any options for exporting.


1 Like

Hi @Nima_Hojat,

Use a ResultsTable and you can export using the table’s File>Save As command, by right-clicking on the table and selecting “Save As” from the drop down menu or by using ImageJ’s File>Save As>Results command.

1 Like

The table window doesn’t have its own menu, but you’ll find File > Export > Table… in the menu of the main ImageJ window (i.e. toolbar) in an up-to-date Fiji.

Please let us know if you have any issues getting your tables saved as files.

1 Like

Hi Jan,
Thank you, I didn’t realise before that the File button is now in the main imageJ window. I was able to export it.

1 Like

Thank you Robert, your solution worked but I added the “results_table.incrementCounter()” instead.

1 Like