I'm using Netbeans to design a JFrame. Using Cardlayout I created two JFrames in ParentPanel. I want to switch between the panels if the button is pressed.
    MotherPanel.removeAll();
    MotherPanel.add(detailPanel);
    MotherPanel.repaint();
    MotherPanel.revalidate();
    detail();
The method detail() accesses the table in database and set specific values to Jtextfields.
public void detail(){
    doConnect();
    setTitle(cur_categ);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);        
}
public void connection() throws SQLException{
    stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                ResultSet.CONCUR_UPDATABLE);
    String SQL = String.format("SELECT * FROM %s", cur_categ);
    rs_det = stmt.executeQuery(SQL);
}
public void doConnect(){
    try{
        //Connect to the database
        String host = "jdbc:derby://localhost:1527/Employees";
        String userName = "App";
        String pass = " ";
        con = DriverManager.getConnection(host, userName, pass);
        connection();
        //Move the cursor to the first record and get the data if there is any
        if (rs_det.next()){                
            double exp_dou = rs_det.getDouble("Expense");
            String exp = Double.toString(exp_dou);             
            String desc = rs_det.getString("Description");
            String date = rs_det.getString("Date");
         //Display the records in the text fields
         textExpense1.setText(exp);
         textDescription.setText(desc);
         textDate.setText(date);               
        }                          
    }
    catch ( SQLException err ){
        JOptionPane.showMessageDialog(this, err.getMessage());
    }  
}
There are several tables in the database that the second frame accesses depending on the chosen row in the jtable in the first Jpanel. I can open second Jpanel, but I cannot reopen it when it accesses the table with values in database. However, I can reopen second Jpanel if there is no values in the table. How can I fix it?
