I have two JFrame Forms-SelectContactsfrm.java and Taskfrm.java. There is JTable in SelectContactsfrm file to show the contacts.When user select a contact from JTable and when he/she press OK button,selected values should be copied into Taskfrm.java’s JTextField.
Taskfrm.java’s JTextField’s name is-txtContacts and access modifier is-public
Below is the code which I wrote on SelectContactsfrm’s OK button’s actionPerformed.Button name-btnOK
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
// Code to get the selected rows value and paste Contact's full name in Taskfrm's txtContacts JTextField:
selrow=ctable.getSelectedRow();
selcol=ctable.getSelectedColumn();
Object value=ctable.getModel().getValueAt(selrow,1);
new Taskfrm().txtContacts.setText(value.toString());
//Just to check whether I get the correct values or not.
System.out.println("selrow=="+selrow);
System.out.println("selcol=="+selcol);
System.out.println("txtContacts=="+value);
}
I can see the correct selected values in output but didnt get why this value has not been set in Taskfrm’s JTextField.In Taskfrm’s constructor only initComponents() is there.Is there any way to attach class files here instead of pasting?
set its visibility and made changes in Taskfrm’s constructor.Now its working.