I am very new to java and i am developing an inventory management system(Its my first project ).I want to add the column values sententiously when a new row is created. please any one help me how to do so.. i want to sum the line total and show it as the arrow is located. .here is my code for table data.
int quantity, price;
Product p = new Product();
String[] result = new String[8];
String data[] = new String[7];
int i = 0;
result=p.getInfo(this.addItemField.getText());
for (String s : result) {
data[i] = s;
i += 1;
}
data[0] = "1";
quantity = Integer.parseInt(data[0]);
price = Integer.parseInt(data[5]);
int tPrice = price*quantity;
data[6] = Integer.toString(tPrice); //this is the field which i want to add for all row.
table.addRow(data);
this.addItemField.grabFocus();
addItemField.setText("");
Add a TableModelListener
to the TableModel
. When a TableModel event is generated you can loop through all the rows in the model and calculate a new total and then update your label.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.