0

I just got this Jtable on Netbeans . First I want it to auto-calculate some grades, as you can see it has 3 columns (1st, 2nd and 3rd evaluation). I have to type between 0 and 100, in each row.

In the end, get the total and average. This can be displayed in a Jlabel, or a textfield. But, it has to be displayed real-time (as I'm typing the values).

Also, I can't type data on all the cells, just one for each row. How do I do this? I know I can change the columns to accept only Integer values, but for everything else, I have no idea how to proceed.

enter image description here

2 Answers2

1

In the end, get the total and average. This can be displayed in a Jlabel, or a textfield. But, it has to be displayed real-time (as I'm typing the values).

Well, you would want to update "after" the user has finished editing a cell and saves the value to the table.

So you can use a TableModelListener. You add the TableModelListener to the TableModel. Then when the data is saved an event will be generated and you can recalculate the values and update the label.

Check out the following for a simple example to get your started: TableModelListener and multiple column validation. Your logic in the listener will change based on your exact requirement.

camickr
  • 321,443
  • 19
  • 166
  • 288
0

You can do this by attaching a defaultTableModel to your JTable. After attaching TableModel to your JTable. You can use command JTable.addRow(Object[]) to add rows to table.