1

How do I get the data of a clicked row to another JFrame? what I mean is, when I click my selected row from the JTable, a new JFrame opens and the information of the clicked row appears. How do I do that? I can only make it appear on the same JFrame, but this time, I need the information to appear in another JFrame. I use NetBeans and MySQL. How do I do that? pls help

I dont know if this would help but here's my code for clicking a row and it appears on the same JFrame(I need it to appear to a different JFrame!):

 private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {    
try{
    int row = jTable1.getSelectedRow();

        String Table_click=(jTable1.getModel().getValueAt(row,0).toString());
        String sql = "Select * from patientrecords where PatID='"+Table_click+"'";
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        if(rs.next()){
            String add1=rs.getString("PatID");
            jTextField2.setText(add1);
             String add2=rs.getString("Ln");
            jTextField3.setText(add2);
             String add3=rs.getString("Fn");
            jTextField4.setText(add3);
             String add4=rs.getString("Mn");
            jTextField5.setText(add4);

            String add6=rs.getString("BD");
            jTextField7.setText(add6);
            String add7=rs.getString("Rel");
            jTextField8.setText(add7);
             String add8=rs.getString("Civ");
            jTextField9.setText(add8);
             String add9=rs.getString("ConNo");
            jTextField10.setText(add9);
             String add10=rs.getString("SchedApp");
            jTextField6.setText(add10);
             String add11=rs.getString("SchedTime");
            jTextField11.setText(add11);
             String add12=rs.getString("RegDate");
            jTextField12.setText(add12);

        }
        else{

        }
    }catch(Exception ab){
        JOptionPane.showMessageDialog(null,ab);
    }                   


}                                    
camickr
  • 321,443
  • 19
  • 166
  • 288
zem
  • 19
  • 2
  • 1
    `I need it to appear to a different JFrame!):` first of all you should be using a JDialog as the the child window, not a frame. Secondly, where do you create the new JDialog? Somewhere in your code you have `new JFrame()`. So now if you want a second window you need to create a `new JDialog()`. Then you add all your text fields to the dialog, just like you did when you created the frame. – camickr Aug 13 '16 at 13:42
  • If your question is _not_ a duplicate, please edit your question to include a [mcve] that shows your revised approach using a `ListSelectionListener`. – trashgod Aug 13 '16 at 15:53

0 Answers0