JavaFX .How to make a line of summation(total row) in the bottom of the table?

后端 未结 3 2032
名媛妹妹
名媛妹妹 2021-01-01 06:06

How to make a line of summation in the bottom of the table(TreeTableView - JavaFX or TableView) ? (Sorry for my english) write an example please.

Picture(Totals) for

3条回答
  •  被撕碎了的回忆
    2021-01-01 06:26

    EDIT :Not the answer of the question. I misunderstood the problem.


    I don't have an example but I can explain you one way of doing it.

    • Use a "TableView"
    • Each column should be a "TableColumn". This "TableColumn" should be related to an "ObsverbableList" with :

      YourColumn.setCellValueFactory(
              cellData ->CellData.getValue().yourObservableList.yourFloatProperty());
      
    • The numbers inside your list should be "FloatProperty".

    • Set a listener on all of them except the last one. (You can do this in a loop)
      • Each listener should call your sum function. This function should calculate the last element of your list = the sum of the other element in the list
      • The "TableView" will automatically update it self.

提交回复
热议问题