private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
        int colCnt = loanScheduleTable.getColumnCount();
        int rowCnt = loanScheduleTable.getRowCount();
        File csvFile = null;
        File renCsvFile = null;
        String newFileName = "";

        JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {


            try {
                csvFile = fc.getSelectedFile();

                newFileName = csvFile.getPath() + ".csv";
                renCsvFile = new File(newFileName);
         
                PrintWriter pw = new PrintWriter(renCsvFile);
                
                for (int i = 0; i < colCnt; ++i) {
                    pw.print(loanScheduleTable.getColumnName(i));

                    if ((i + 1) == colCnt) {
                        pw.print("\n");
                    } else {
                        pw.print(",");
                    }
                }

                for (int row = 0; row < rowCnt; ++row) {
                    for (int col = 0; col < colCnt; ++col) {
                        String value = String.valueOf(loanScheduleTable.getValueAt(row, col));

                        if (value.equalsIgnoreCase("null")) {
                            pw.print("");
                        } else {
                            pw.print(value);
                        }


                        if ((col + 1) == colCnt) {
                            pw.print("\n");
                        } else {
                            pw.print(",");
                        }
                    }
                }

                pw.flush();
                pw.close();
                
                JOptionPane.showMessageDialog(rootPane, "Successfully Saved to " + newFileName, "Information",
                JOptionPane.INFORMATION_MESSAGE);
            } catch (IOException ex) {
                printErrorMsg(ex, "unable to export file");
            }

        } else {
            // nothing to do
        }



    }//GEN-LAST:event_exportButtonActionPerformed