javajavafx-2javafx

TableView Cell Span


Is there any way to make a TableCell span horizontally? I want to create a tableview in JavaFX 2.2 similar to the one showed in the attached image

sample
(source: fxexperience.com)

By the way, the image came from a sample of this funcionality but it is specific for Java FX 8.0. I've been trying to use a rowFactory but there isn't enough documentation on how to use it.

Thanks in advance.


Solution

  • Cell spanning in the JavaFX platform was implemented for Java 8, then cut as part of feature trim.
    It may go into a future release.

    The feature request to track for cell spanning is RT-24747 Cell spanning / merging in TableView1. Which is just the feature request that provided the image referenced in your question.

    The linked feature request includes sample code for showing a table with row and column spanning for cells. The sample code relies on a patch attached to the feature request. The patch modifies JavaFX controls code for Java 8.

    You can study the code and patch in the feature request to determine if you can implement such technology for yourself in user code without patching the JavaFX runtime.


    The only code I know which customizes the row factory is the code in openjfx for the default TableView row handling - and that's not straightforward. For reference, the code is in TableRow.java, TableRowSkinBase.java and TableRowSkin.java.

    An alternative to implementing your own row factory is Updating TableView row appearance, that uses css to modify the style of certain cells or an entire row rather than making use of a completely custom row factory. Rather than implementing an entirely new row factory, you may be able to get the effect you want by modifying css styles to remove line separators between spanned cells .

    Use of the ScenicView or the SceneBuilder CSS Analyzer tools may assist in determining the required css styles to be modified.


    1. Unfortunately the feature request link RT-24747 is dead, as the JavaFX bug tracker was merged into OpenJDK, and I don't know the equivalent link in the current bug tracker. As far as I know the feature was never implemented.