如何解决如何使用 JTextFields
我有它,所以当我单击一行时,所有信息都显示在 JTextFields 上,但我想知道如果用户随后进行更改,我该如何使用它来更新条目?
String[] columnNames = {"ID","FirstName","Surname","Email","Phone","Street","City","County","Eircode"};
DefaultTableModel tableModel = new DefaultTableModel(columnNames,0);
while(rs.next()) {
String ID = rs.getString("idCustomer");
String FirstName = rs.getString("FirstName");
String Surname = rs.getString("Surname");
String Email = rs.getString("Email");
String Phone = rs.getString("Phone");
String Street = rs.getString("Street");
String City = rs.getString("City");
String County = rs.getString("County");
String Eircode = rs.getString("Eircode");
// Row data
String[] data = {ID,FirstName,Surname,Email,Phone,Street,City,County,Eircode};
// Add row
tableModel.addRow(data);
}
// JTable
table = new JTable(tableModel);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.setFillsViewportHeight(true);
pTable.add(new JScrollPane(table)); // Allows column names to be displayed
ListSelectionModel model = table.getSelectionModel();
model.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int selectedRow = table.getSelectedRow();
id1.setText(table.getValueAt(selectedRow,0).toString());
fName1.setText(table.getValueAt(selectedRow,1).toString());
surname1.setText(table.getValueAt(selectedRow,2).toString());
email1.setText(table.getValueAt(selectedRow,3).toString());
phone1.setText(table.getValueAt(selectedRow,4).toString());
street1.setText(table.getValueAt(selectedRow,5).toString());
city1.setText(table.getValueAt(selectedRow,6).toString());
county1.setText(table.getValueAt(selectedRow,7).toString());
eircode1.setText(table.getValueAt(selectedRow,8).toString());
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。