0

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));
        }
    });
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Mike1918
  • 1
  • 2
  • 1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 3) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 4) .. – Andrew Thompson May 02 '18 at 14:40
  • .. 4) There is likely a better listener for a `JTable` - one that, for example, detects table row selection originating from keyboard actions. 5) *"However I am having problems with setting the data to the JTextFields in the other JFrame."* ***What problems?*** Please be specific, as we are not mind readers. 6) .. And as an aside, what is your *question?* – Andrew Thompson May 02 '18 at 14:41
  • I think that makes my problem clearer?, In terms of 4) there is a row listener for what you've described – Mike1918 May 02 '18 at 14:55
  • See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) – Andrew Thompson May 02 '18 at 20:29

0 Answers0