So I want to on mouse click of a row take data from this selected row in a JTable
in one JFrame
and insert the data into another JFrame
with different JComponents
.
To this point I have set up the mouse listener and taken data from the selected row and stored it in variables. However I am having problems with setting the data to the JTextFields
in the other JFrame
. The problem is that 'JTextFields' are not showing any data nor is the println System.out.println(taskName);
added to this after a mouse click I'm getting this exception Exception in thread "AWT EventQueue-0" java.lang.NullPointerException
.
Below is the mouse listener code, if anymore code is needed I can provide this.
editFrame jtRowData = new editFrame();
tblCurrentTasks.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
int index = tblCurrentTasks.getSelectedRow();
DefaultTableModel model = (DefaultTableModel) tblCurrentTasks.getModel();
String taskID = model.getValueAt(index, 0).toString();
String taskName = model.getValueAt(index, 1).toString();
String taskDes = model.getValueAt(index, 2).toString();
String taskIm = model.getValueAt(index, 3).toString();
String taskFre = model.getValueAt(index, 4).toString();
String taskDr = model.getValueAt(index, 5).toString();
System.out.println(taskID);
System.out.println(taskName);
System.out.println(taskDes);
System.out.println(taskIm);
System.out.println(taskFre);
System.out.println(taskDr);
jtRowData.txtTaskName.setText(taskName);
jtRowData.txtTaskDesc.setText(taskDes);
System.out.println(taskName);
jtRowData.setVisible(true);
jtRowData.pack();
jtRowData.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jtRowData.setBounds(200, 200, 550, 370);
jtRowData.setLocation(new Point(700, 300));
}
});
}