i want to update the JTable date by mouse selecting the cell and input the new data inside the JTextField and using a button to update? i am using Vector method, i stuck this problem in 2 weeks but i still not foung the solutions. Please help!
public class GUI extends JFrame {
private JPanel contentPane;
private JTable table;
private JTextField textField;contentPane = new JPanel();
public GUI() throws Exception {
contentPane.setBackground(Color.LIGHT_GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
Data entry = new Data();
Attributes[] x = new Attributes[100];
for(int i = 0;i<x.length;i++){
x[i] = new Attributes();
}
Data.loadxml(x);
for(int i = 0;i<x.length;i++){
Vector<Object> row = new Vector<Object>();
row.add( x[i].getbrand());
row.add( x[i].getbuyCurrency());
row.add( x[i].getbuyPrice());
row.add( x[i].getcategory());
row.add( x[i].getid());
row.add( x[i].getleadTime());
row.add( x[i].getminOrderQuantity());
row.add( x[i].getname());
row.add( x[i].getsellPrice());
row.add( x[i].getstockOnHand());
row.add( x[i].getstockOnOrder());
row.add( x[i].getsubCategory());
row.add( x[i].getsupplier());
row.add( x[i].gettargetBatchVolume());
row.add( x[i].getvolume());
data.add(row);
}
Vector<Object> headers = new Vector<Object>();
headers.add( "Brand");
headers.add( "Buy Currency");
headers.add( "Buy Price");
headers.add( "Category");
headers.add( "ID");
headers.add( "Lead Time");
headers.add( "Min Order Quantity");
headers.add( "Name");
headers.add( "Sell Price");
headers.add( "Stock On Hand");
headers.add( "Stock On Order");
headers.add( "Sub Category");
headers.add( "Supplier");
headers.add( "Target Batch Volume");
headers.add( "Volume");
contentPane.setLayout(null);
JTable table = new JTable(data, headers);
table.getSelectedRow();
table.getSelectedColumn();
table.setBounds(12, 13, 1020, 500);
resizeColumnWidth(table);
resizeColumnWidthByHeader(table);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setAutoCreateRowSorter(true);
TableColumn col=table.getColumnModel().getColumn(0);
contentPane.add(table);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(12, 109, 1391, 771);
contentPane.add(scrollPane);
JButton btnSubmit = new JButton("Submit");
btnSubmit.setFont(new Font("Yu Gothic UI Semilight", Font.PLAIN, 15));
btnSubmit.setBounds(1155, 53, 99, 27);
contentPane.add(btnSubmit);
textField = new JTextField();
textField.setBounds(886, 56, 219, 25);
contentPane.add(textField);
textField.setColumns(10);