Automatic row numbering in javafx table

前端 未结 1 1406
旧巷少年郎
旧巷少年郎 2021-01-02 12:34

I have a sample code that we use to dynamic row numbers in Java Swing Table i.e JTable. I new to JavaFX and would like to

相关标签:
1条回答
  • 2021-01-02 13:05

    In JavaFX, you use TableColumns with CellFactories and CellValueFactories to populate your TableView.

    The JavaFX tutorials have an article that might get you started.

    In one approach I have used I convert the business objects to display into presentation objects and add all necessary properties (like in your case, the number) to them.

    EDIT: In a second, cleaner approach, you could set your CellFactory to create a TableCell that shows its own index property in TableCell#updateItem(S, boolean):

    public class NumberedCell extends TableCell{
    
      protected void updateItem(Object object, boolean selected){
        setText(String.valueOf(getIndex());
      }
    }
    
    0 讨论(0)
提交回复
热议问题