I have two windows: PatientWindow and CreateEditPatientWindow. In PatientWindow I have JTable which is populated from text files. Also, on the PatientWindow I have button 'Update' which open CreateEditPatientWindow. So I want to populate TextFields in CreateEditPatientWindow with data of selected item from table in PatientWindow.
Here i update button listener. Here i successed to print line the correct username of selected user in table:
btnUpdate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int row = tblPatients.getSelectedRow();
if(row == -1)
{
JOptionPane.showMessageDialog(null, "You must select row for update", "Info", JOptionPane.WARNING_MESSAGE);
}
else
{
DefaultTableModel model = (DefaultTableModel)tblPatients.getModel();
String username = model.getValueAt(row, 6).toString();
UserModel userSearch = UsersClass.findUser(username);
if(userSearch != null)
{
System.out.println("USER FOUND!!!" + username);
CreateEditPatientWindow createEditPatientWindow = new CreateEditPatientWindow();
createEditPatientWindow.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null, "User not found", "Info", JOptionPane.ERROR_MESSAGE);
}
}
}
});
So in CreateEditPatientWindow one of TextFields is txtUsername.
lblUsername = new JLabel("Username");
txtUsername = new JTextField(20);
// txtUsername.setText(USERNAME VALUE FROM PatientWindow)