How can I calculate sum of price column in jTable
and put sum of them at the end of the jTable
. Can you give me a sample code?
public class IncomeReport extends JFrame {
private AccountFacade service = new AccountFacade();
void init() {
String[] columnNames = {"مبلغ", "محل درآمد ", "منبع"};
List list = service.incomeReportFacade();
Object[][] model = new Object[list.size()][];
for (int i = 0; i < list.size(); i++) {
model[i] = (Object[]) list.get(i);
}
JTable table = new JTable(model, columnNames) {
DefaultTableCellRenderer renderRight = new DefaultTableCellRenderer();
{
// initializer block
renderRight.setHorizontalAlignment(SwingConstants.RIGHT);
}
@Override
public TableCellRenderer getCellRenderer(int arg0, int arg1) {
return renderRight;
}
};
Try something like this. Get the model, and use the
DefaultTableModel#getValueAt()
method.