Example usage for javax.swing.table DefaultTableModel removeRow

List of usage examples for javax.swing.table DefaultTableModel removeRow

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel removeRow.

Prototype

public void removeRow(int row) 

Source Link

Document

Removes the row at row from the model.

Usage

From source file:interfaces.InterfazPrincipal.java

private void botonRegistrarAbonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonRegistrarAbonoActionPerformed
    // TODO add your handling code here:
    try {/*from   w w w.  jav a 2 s.co  m*/

        String identificacionCliente = mostrarIdentificacionCliente.getText();
        Double abono = Double.parseDouble(abonoClente.getText());

        if (abono <= 0.0) {
            throw new Exception();
        }

        ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura();
        ControladorFactura controladorFactura = new ControladorFactura();

        Calendar calendario = Calendar.getInstance();
        String dia = Integer.toString(calendario.get(Calendar.DATE));
        String mes = Integer.toString(calendario.get(Calendar.MONTH));
        String annio = Integer.toString(calendario.get(Calendar.YEAR));
        Date date = new Date();
        DateFormat hourFormat = new SimpleDateFormat("HH:mm:ss");
        String hora = hourFormat.format(date);

        String fecha = annio + "-" + mes + "-" + dia + " " + hora;
        /*
         * -----------------Tomar el abono y los pagos-----------------
         * Procedimiento
         * 1 Tomar flujos de deuda de cada factura con estado fiado
         * 2 Tomar abonos de abono de cada factura con estado fiado
         * 3 Calcular la resta de estos dos para deteminar lo que se debe por factura
         * 4 Cancelar con el flujo la factura y si lo debido es 0 colocar estado pagado
         * 5 Mostrar una informacin en un JOptionPane y recalcular la deuda
         * 
         */
        DefaultTableModel modeloClientes = (DefaultTableModel) TablaDeSaldoClientes.getModel();
        ArrayList<String> codigoFactura = new ArrayList<>();
        ArrayList<Double> totalDebe = new ArrayList<>();

        JTextArea area = new JTextArea(10, 30);
        String informe = "\t Registro flujo pago del abono \n\n";
        informe += "Factura \t Pago \t Queda pagada? \n\n";

        int numeroRegistros = -1;
        for (int i = 0; i < modeloClientes.getRowCount(); i++) {
            //System.out.println("Entro al for " + i);
            //Se necesita 0: Factura ID, 1 Tipo, 3 Valor
            // Codigofactura contiene los cogidos de las facturas
            // totalDebe contiene lo que debe de las facturas, la posicion coincide con la lista CodigoFactura
            String factura_id = String.valueOf(modeloClientes.getValueAt(i, 0));
            String tipo_flujo = String.valueOf(modeloClientes.getValueAt(i, 1));
            Double valor = Double.parseDouble(String.valueOf(modeloClientes.getValueAt(i, 3)));
            if (codigoFactura.contains(factura_id)) {

                if (tipo_flujo.equals("abono")) {
                    totalDebe.set(numeroRegistros, totalDebe.get(numeroRegistros) - valor);
                } else {
                    totalDebe.set(numeroRegistros, totalDebe.get(numeroRegistros) + valor);
                }
            } else {
                numeroRegistros++;
                codigoFactura.add(factura_id);
                if (tipo_flujo.equals("abono")) {
                    totalDebe.add(-valor);
                } else {
                    totalDebe.add(valor);
                }
            }

        }
        //System.out.println(Arrays.toString(codigoFactura.toArray()));
        //System.out.println(Arrays.toString(totalDebe.toArray()));
        Double debeTotal = 0d;
        for (int i = 0; i < totalDebe.size(); i++) {
            debeTotal += totalDebe.get(i);

        }

        if (debeTotal < abono) {
            JOptionPane.showMessageDialog(this,
                    "El monto es superior a lo que debe el cliente, por favor indique otro monto", "Error",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        for (int i = 0; i < totalDebe.size(); i++) {
            //Tomar flujos
            if (abono > 0.0) {
                Double pago = totalDebe.get(i) - abono;

                //Pago igual a 0 significa que se pag la factura
                if (pago == 0) {
                    //Registrar flujo
                    String[] value = { codigoFactura.get(i), "abono", fecha, String.valueOf(abono) };
                    //String [] selection = {"factura_id","tipo_flujo","fecha","valor"};
                    controladorFlujoFactura.insertFlujo_Factura(value);

                    controladorFactura.cambiarEstadoFactura(codigoFactura.get(i), "pagada");
                    informe += codigoFactura.get(i) + "\t" + String.valueOf(abono) + "\tSI\n";
                    //Romper el for
                    break;
                } else {

                    //Pago mayor que 0, es decir se queda debiendo
                    if (pago > 0) {

                        //Registrar flujo
                        String[] value = { codigoFactura.get(i), "abono", fecha, String.valueOf(abono) };
                        //String [] selection = {"factura_id","tipo_flujo","fecha","valor"};
                        controladorFlujoFactura.insertFlujo_Factura(value);
                        //Como el abono ahora es menor que 0 debe romperse el for
                        informe += codigoFactura.get(i) + "\t" + String.valueOf(abono) + "\tNO\n";

                        break;

                    } else {
                        //Caso final pago menor 0, es decir el abono paga la factura pero queda disponible para otras facturas
                        //Registrar flujo
                        String[] value = { codigoFactura.get(i), "abono", fecha,
                                String.valueOf(totalDebe.get(i)) };
                        //String [] selection = {"factura_id","tipo_flujo","fecha","valor"};
                        controladorFlujoFactura.insertFlujo_Factura(value);

                        controladorFactura.cambiarEstadoFactura(codigoFactura.get(i), "pagada");

                        //Ajustamos ahora el abono restando lo que debe la factura
                        informe += codigoFactura.get(i) + "\t" + String.valueOf(abono) + "\tSI\n";
                        abono -= totalDebe.get(i);
                    }

                }
            } else {
                //Romper el for
                break;
            }

        }

        //Reordenar y volver a consultar
        for (int i = 0; i < modeloClientes.getRowCount(); i++) {
            modeloClientes.removeRow(i);
        }

        modeloClientes.setRowCount(0);

        //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506);
        ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura(
                " where factura_id in (select factura_id from Factura where cliente_id = "
                        + String.valueOf(identificacionCliente) + " and estado=\"fiado\") order by factura_id");
        double pago = 0.0;

        for (int i = 0; i < flujosCliente.size(); i++) {
            String[] datos = flujosCliente.get(i);
            Object[] rowData = { datos[1], datos[2], datos[3], datos[4] };
            modeloClientes.addRow(rowData);
            if (datos[2].equals("deuda")) {
                pago += Double.parseDouble(datos[4]);
            } else {
                pago -= Double.parseDouble(datos[4]);
            }
        }

        textoTotalDebe.setText(String.valueOf(pago));
        TablaDeSaldoClientes.setModel(modeloClientes);
        area.setText(informe);
        JScrollPane panelInformePago = new JScrollPane(area);
        JOptionPane.showMessageDialog(this, panelInformePago);

    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Debe ingresar un valor numrico mayor que 0 en el abono ");
    }
}

From source file:interfaces.InterfazPrincipal.java

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
    // TODO add your handling code here:

    try {//  w  w  w. j a  v a2s  . com

        String identificacionCliente = mostrarIDProveedor.getText();
        Double abono = Double.parseDouble(jTextFieldAbonoProveedor.getText());

        if (abono <= 0.0 || identificacionCliente.equals("")) {
            throw new Exception();
        }

        ControladorFlujoCompras controladorFlujoFactura = new ControladorFlujoCompras();
        ControladorCompraProveedor controladorCompraProveedor = new ControladorCompraProveedor();

        Calendar calendario = Calendar.getInstance();
        String dia = Integer.toString(calendario.get(Calendar.DATE));
        String mes = Integer.toString(calendario.get(Calendar.MONTH));
        String annio = Integer.toString(calendario.get(Calendar.YEAR));
        Date date = new Date();
        DateFormat hourFormat = new SimpleDateFormat("HH:mm:ss");
        String hora = hourFormat.format(date);

        String fecha = annio + "-" + mes + "-" + dia + " " + hora;
        /*
         * -----------------Tomar el abono y los pagos-----------------
         * Procedimiento
         * 1 Tomar flujos de deuda de cada factura con estado fiado
         * 2 Tomar abonos de abono de cada factura con estado fiado
         * 3 Calcular la resta de estos dos para deteminar lo que se debe por factura
         * 4 Cancelar con el flujo la factura y si lo debido es 0 colocar estado pagado
         * 5 Mostrar una informacin en un JOptionPane y recalcular la deuda
         * 
         */
        DefaultTableModel modeloClientes = (DefaultTableModel) TablaDeSaldoProveedor.getModel();
        ArrayList<String> codigoFactura = new ArrayList<>();
        ArrayList<Double> totalDebe = new ArrayList<>();

        JTextArea area = new JTextArea(10, 30);
        String informe = "\t Registro flujo pago del abono \n\n";
        informe += "Factura \t Pago \t Queda pagada? \n\n";

        int numeroRegistros = -1;
        for (int i = 0; i < modeloClientes.getRowCount(); i++) {
            //System.out.println("Entro al for " + i);
            //Se necesita 0: Factura ID, 1 Tipo, 3 Valor
            // Codigofactura contiene los cogidos de las facturas
            // totalDebe contiene lo que debe de las facturas, la posicion coincide con la lista CodigoFactura
            String factura_id = String.valueOf(modeloClientes.getValueAt(i, 0));
            String tipo_flujo = String.valueOf(modeloClientes.getValueAt(i, 1));
            Double valor = Double.parseDouble(String.valueOf(modeloClientes.getValueAt(i, 3)));
            if (codigoFactura.contains(factura_id)) {

                if (tipo_flujo.equals("abono")) {
                    totalDebe.set(numeroRegistros, totalDebe.get(numeroRegistros) - valor);
                } else {
                    totalDebe.set(numeroRegistros, totalDebe.get(numeroRegistros) + valor);
                }
            } else {
                numeroRegistros++;
                codigoFactura.add(factura_id);
                if (tipo_flujo.equals("abono")) {
                    totalDebe.add(-valor);
                } else {
                    totalDebe.add(valor);
                }
            }

        }
        //System.out.println(Arrays.toString(codigoFactura.toArray()));
        //System.out.println(Arrays.toString(totalDebe.toArray()));
        System.out.println(totalDebe);
        double debeTotal = 0d;
        for (int i = 0; i < totalDebe.size(); i++) {
            debeTotal += totalDebe.get(i);
        }

        if (debeTotal < abono) {
            JOptionPane.showMessageDialog(this, "El monto a pagar no puede ser superior a lo que se debe",
                    "Error del sistema", JOptionPane.ERROR_MESSAGE);
            return;
        }
        for (int i = 0; i < totalDebe.size(); i++) {
            //Tomar flujos
            if (abono > 0.0) {
                Double pago = totalDebe.get(i) - abono;

                //Pago igual a 0 significa que se pag la factura
                if (pago == 0) {
                    //Registrar flujo
                    //String[] value = {codigoFactura.get(i), "abono", fecha, String.valueOf(abono)};
                    //String [] selection = {"factura_id","tipo_flujo","fecha","valor"};
                    controladorFlujoFactura.registrarFlujoAbono(codigoFactura.get(i), String.valueOf(abono));

                    //controladorFactura.cambiarEstadoFactura(codigoFactura.get(i), "pagada");
                    informe += codigoFactura.get(i) + "\t" + String.valueOf(abono) + "\tSI\n";
                    //Romper el for
                    break;
                } else {

                    //Pago mayor que 0, es decir se queda debiendo
                    if (pago > 0) {

                        //Registrar flujo
                        //String[] value = {codigoFactura.get(i), "abono", fecha, String.valueOf(abono)};
                        //String [] selection = {"factura_id","tipo_flujo","fecha","valor"};
                        controladorFlujoFactura.registrarFlujoAbono(codigoFactura.get(i),
                                String.valueOf(abono));
                        //Como el abono ahora es menor que 0 debe romperse el for
                        informe += codigoFactura.get(i) + "\t" + String.valueOf(abono) + "\tNO\n";

                        break;

                    } else {
                        //Caso final pago menor 0, es decir el abono paga la factura pero queda disponible para otras facturas
                        //Registrar flujo
                        //String[] value = {codigoFactura.get(i), "abono", fecha, String.valueOf(totalDebe.get(i))};
                        //String [] selection = {"factura_id","tipo_flujo","fecha","valor"};
                        controladorFlujoFactura.registrarFlujoAbono(codigoFactura.get(i),
                                String.valueOf(totalDebe.get(i)));

                        //controladorFactura.cambiarEstadoFactura(codigoFactura.get(i), "pagada");
                        //Ajustamos ahora el abono restando lo que debe la factura
                        informe += codigoFactura.get(i) + "\t" + String.valueOf(abono) + "\tSI\n";
                        abono -= totalDebe.get(i);
                    }

                }
            } else {
                //Romper el for
                break;
            }

        }

        //Reordenar y volver a consultar
        for (int i = 0; i < modeloClientes.getRowCount(); i++) {
            modeloClientes.removeRow(i);
        }

        modeloClientes.setRowCount(0);

        //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506);
        ArrayList<Flujo_Compra> flujosProveedor = controladorFlujoFactura.obtenerFlujosCompras(
                " where ID_CompraProveedor in (select ID_CompraProveedor from Compra_Proveedores where IDProveedor = "
                        + String.valueOf(identificacionCliente) + ") order by ID_CompraProveedor");
        double pago = 0.0;

        for (int i = 0; i < flujosProveedor.size(); i++) {
            Flujo_Compra datos = flujosProveedor.get(i);
            Object[] rowData = { datos.getID_CompraProveedor(), datos.getTipo_flujo(), datos.getFecha(),
                    datos.getMonto() };

            if (datos.getTipo_flujo().equals("deuda")) {
                pago += Double.parseDouble(datos.getMonto() + "");
            } else {
                pago -= Double.parseDouble(datos.getMonto() + "");
            }

            modeloClientes.addRow(rowData);
        }

        TablaDeSaldoProveedor.setModel(modeloClientes);
        deudaActualProveedor.setText(String.valueOf(pago));

        //Mostrar en table de clientes los datos
        botonRegistrarAbono.setEnabled(true);

        area.setText(informe);
        JScrollPane panelInformePago = new JScrollPane(area);
        JOptionPane.showMessageDialog(this, panelInformePago);

    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Debe ingresar un valor numrico mayor que 0 en el abono ");
    }

}

From source file:org.signserver.admin.gui.AddWorkerDialog.java

private void removeProperty(final String key) {
    final DefaultTableModel model = (DefaultTableModel) propertiesTable.getModel();

    for (int i = 0; i < model.getRowCount(); i++) {
        if (key.equals(model.getValueAt(i, 0))) {
            model.removeRow(i);
            break;
        }/*from   w  ww .  jav a2  s  .co  m*/
    }
}

From source file:org.signserver.admin.gui.AddWorkerDialog.java

private void removePropertyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePropertyButtonActionPerformed
    final int row = propertiesTable.getSelectedRow();

    if (row != -1) {
        final DefaultTableModel model = (DefaultTableModel) propertiesTable.getModel();

        model.removeRow(row);
    }/*from www. ja  v  a2s  .  c  o  m*/
}

From source file:org.spottedplaid.ui.Mainframe.java

/**
 * Create the frame./*from  ww  w . j av a2 s.c o m*/
 *
 * @param _Sqliteops the _ sqliteops
 * @param _Crypto the _ crypto
 */
public Mainframe(SQliteOps _Sqliteops, Crypto _Crypto) {

    l_sqliteops = _Sqliteops;
    l_crypto = _Crypto;

    setTitle("The Password Saver - Management");
    setResizable(false);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 982, 656);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    menuBar.add(mnFile);

    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            System.exit(0);
        }
    });

    mnFile.add(mntmExit);

    JMenu mnTools = new JMenu("Tools");
    menuBar.add(mnTools);

    JMenuItem mntmChgpwd = new JMenuItem("Change Passphrase");
    mntmChgpwd.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Changepwd changePwd = new Changepwd(l_crypto, l_sqliteops);
            changePwd.setVisible(true);
        }
    });

    mnTools.add(mntmChgpwd);

    JMenuItem mntmExpirationReport = new JMenuItem("Expiration Report");
    mntmExpirationReport.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            DbRecord dbRecExp = new DbRecord();
            dbRecExp.setType(Pwdtypes.S_EXP_RPT);
            ArrayList<String> arrData = l_sqliteops.getRecords(dbRecExp);
            String[] sRecord = new String[3];
            String sData = "";
            int iElement = 0;

            /// Cycle through the data, output to text file, and open in WordPad
            if (arrData != null && arrData.size() > 0) {
                try {
                    String sFilename = "ExpirationReport.txt";
                    File fileExpRpt = new File(sFilename);

                    BufferedWriter buffWriter = new BufferedWriter(new FileWriter(fileExpRpt));
                    buffWriter.write("URL/Application                Challenge            Expiration");
                    buffWriter.write("\n");
                    buffWriter.write("--------------------------------------------------------------");
                    buffWriter.write("\n");
                    for (int iCount = 0; iCount < arrData.size(); iCount++) {
                        sData = arrData.get(iCount);
                        System.out.println("DEBUG->sData [" + sData + "]");
                        StringTokenizer st = new StringTokenizer(sData, "|");
                        iElement = 0;
                        while (st.hasMoreTokens()) {
                            sRecord[iElement] = st.nextToken();
                            iElement++;
                        }

                        /// Define the padding for the output
                        int iPadValue1 = 35 - sRecord[0].length();
                        if (iPadValue1 < 0) {
                            iPadValue1 = 2;
                        }

                        int iPadValue2 = 55 - (35 + sRecord[1].length());
                        if (iPadValue2 < 0) {
                            iPadValue2 = 2;
                        }

                        iPadValue1 += sRecord[1].length();
                        iPadValue2 += sRecord[2].length();

                        buffWriter.write(sRecord[0] + StringUtils.leftPad(sRecord[1], iPadValue1)
                                + StringUtils.leftPad(sRecord[2], iPadValue2) + "\n");
                        buffWriter.write("\n");
                    }
                    buffWriter.close();

                    /// Opens WordPad on Windows systems.  This could be changed to use a property in order to work on a linux/unix/apple system
                    ProcessBuilder pb = new ProcessBuilder("write.exe", sFilename);
                    pb.start();
                } catch (IOException ie) {
                    System.out.println("Expiration Report IO Exception [" + ie.getMessage() + "]");
                    ie.printStackTrace();
                }

            } else {
                JOptionPane.showMessageDialog(null, "No expiring records found");
            }
        }
    });
    mnTools.add(mntmExpirationReport);

    JMenuItem mntmViewLogs = new JMenuItem("View Logs");
    mntmViewLogs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DbRecord dbRecLogs = new DbRecord();
            dbRecLogs.setType(Pwdtypes.S_LOG_TYPE);
            ArrayList<String> arrData = l_sqliteops.getRecords(dbRecLogs);
            String[] sRecord = new String[3];
            String sData = "";
            String sTitle = "Display Data Changes";
            String sDisplay = "Date                  Log Message";
            sDisplay += "\n";
            int iElement = 0;

            /// Cycle through the data, output to text file, and open in WordPad
            if (arrData != null) {
                for (int iCount = 0; iCount < arrData.size(); iCount++) {
                    sData = arrData.get(iCount);
                    System.out.println("DEBUG->sData [" + sData + "]");
                    StringTokenizer st = new StringTokenizer(sData, "|");
                    iElement = 0;
                    while (st.hasMoreTokens()) {
                        sRecord[iElement] = st.nextToken();
                        iElement++;
                    }
                    sDisplay += sRecord[2] + ":" + sRecord[1];
                    sDisplay += "\n";
                }

                if (arrData.size() > 0) {
                    JOptionPane.showMessageDialog(null, sDisplay, sTitle, JOptionPane.INFORMATION_MESSAGE);
                }

            }
        }
    });

    mnTools.add(mntmViewLogs);

    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);

    JLabel lblThePasswordSaver = new JLabel("The Password Saver - Manage Passwords");
    lblThePasswordSaver.setFont(new Font("Arial", Font.BOLD, 16));
    lblThePasswordSaver.setHorizontalAlignment(SwingConstants.CENTER);

    JLabel lblUrlapplication = new JLabel("URL/Application");

    jtxtApp = new JTextField();
    jtxtApp.setColumns(10);

    JLabel lblDescription = new JLabel("Description");

    jtxtDesc = new JTextField();
    jtxtDesc.setColumns(10);

    /// Button - Add button for clients/apps
    JButton btnAdd = new JButton("Add");
    btnAdd.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (FormValidation.verifyAppData(jtxtApp.getText().toString(), jtxtDesc.getText().toString()) < 0) {
                JOptionPane.showMessageDialog(null, "URL/Application and Description are required");
            } else {
                dbRec = new DbRecord();
                dbRec.setType(Pwdtypes.S_CLIENT_TYPE);
                dbRec.setClientName(jtxtApp.getText().toString());
                dbRec.setClientDesc(jtxtDesc.getText().toString());
                int l_iClientId = l_sqliteops.insertRecord(dbRec);
                if (l_iClientId <= 0) {
                    JOptionPane.showMessageDialog(null, "Insert record failed [" + dbRec.getResult() + "]");
                } else {
                    dbRec.setClientId(l_iClientId);
                    addToTable();
                }
            }
        }
    });

    /// Buttons - Replace button for clients/apps
    btnReplace = new JButton("Replace");
    btnReplace.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (iClientId <= 0) {
                JOptionPane.showMessageDialog(null, "Update record warning: Please select record to continue");
                return;
            }
            dbRec = new DbRecord();
            dbRec.setType(Pwdtypes.S_CLIENT_TYPE);
            dbRec.setClientId(iClientId);
            dbRec.setClientName(jtxtApp.getText().toString());
            dbRec.setClientDesc(jtxtDesc.getText().toString());
            if (l_sqliteops.updateRecord(dbRec) < 0) {
                JOptionPane.showMessageDialog(null, "Update record failed [" + dbRec.getResult() + "]");
            } else {
                int iRow = jtabApps.getSelectedRow();
                jtabApps.setValueAt(jtxtApp.getText().toString(), iRow, 1);
                jtabApps.setValueAt(jtxtDesc.getText().toString(), iRow, 2);

                clearFields();
            }
        }
    });

    btnReplace.setEnabled(false);

    /// Button - Delete button for clients/apps
    btnDelete = new JButton("Delete");
    btnDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (iClientId <= 0) {
                JOptionPane.showMessageDialog(null,
                        "Delete record failed: Please select a record then click Delete");
                return;
            }
            dbRec = new DbRecord();
            dbRec.setType("clients");
            dbRec.setClientId(iClientId);
            dbRec.setDelCreds(0);

            if (chkDelAssoc.isSelected()) {
                dbRec.setDelCreds(1);
            }

            if (l_sqliteops.deleteRecord(dbRec) < 0) {
                JOptionPane.showMessageDialog(null, "Delete record failed [" + dbRec.getResult() + "]");
            } else {
                DefaultTableModel jtabModel = (DefaultTableModel) jtabApps.getModel();
                jtabModel.removeRow(jtabApps.getSelectedRow());
                if (chkDelAssoc.isSelected()) {
                    DefaultTableModel model = (DefaultTableModel) jtabCreds.getModel();
                    model.setRowCount(0);
                }
                clearFields();
            }
        }
    });
    btnDelete.setEnabled(false);

    /// Buttons - Search button for clients/apps
    btnSearch = new JButton("Search");
    btnSearch.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dbRec = new DbRecord();
            dbRec.setType(Pwdtypes.S_CLIENT_TYPE);
            dbRec.setClientName(jtxtApp.getText().toString());
            dbRec.setClientDesc(jtxtDesc.getText().toString());
            loadTable(dbRec);
        }
    });

    btnClear = new JButton("Clear");
    btnClear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            clearFields();
        }
    });

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    /// Begin section for credentials challenges/responses - text fields and buttons
    JLabel lblChallenge = new JLabel("Challenge");

    JLabel lblResponse = new JLabel("Response");

    jtxtChlng = new JTextField();
    jtxtChlng.setColumns(10);

    jtxtRsp = new JTextField();
    jtxtRsp.setColumns(10);

    /// Buttons - Add button for credentials
    btnCredAdd = new JButton("Add");
    btnCredAdd.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (FormValidation.verifyCredData(jtxtChlng.getText().toString(),
                    jtxtRsp.getText().toString()) < 0) {
                JOptionPane.showMessageDialog(null, "Challenge and Response are required");
            } else {
                dbRec = new DbRecord();
                dbRec.setType(Pwdtypes.S_CREDS_TYPE);
                dbRec.setClientId(iClientId);
                dbRec.setChallenge(jtxtChlng.getText().toString());
                dbRec.setResponse(l_crypto.encrypt(jtxtRsp.getText().toString()));
                dbRec.setTrack(jcbTrack.getSelectedItem().toString());

                /// Set the modify date if the track days are > 0
                if (!jcbTrack.getSelectedItem().toString().equals("0")) {
                    Calendar calNow = Calendar.getInstance();
                    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                    int iDaysToAdd = Integer.parseInt(jcbTrack.getSelectedItem().toString());

                    calNow.add(Calendar.DATE, iDaysToAdd);
                    String sValue = sdf.format(calNow.getTime());
                    dbRec.setModifyDate(sValue);
                }

                int l_iClientId = l_sqliteops.insertRecord(dbRec);
                if (l_iClientId <= 0) {
                    JOptionPane.showMessageDialog(null, "Insert record failed [" + dbRec.getResult() + "]");
                } else {
                    dbRec.setCredId(l_iClientId);
                    addToCredsTable();
                }
            }
        }
    });

    /// Button - Replace button for credentials
    btnCredReplace = new JButton("Replace");
    btnCredReplace.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            DbRecord dbRecLog = new DbRecord();
            int iDaysToAdd = 0;
            Calendar calNow = Calendar.getInstance();
            SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy");

            String sCurDate = sdf1.format(calNow.getTime());
            String sValue = sDateModified;
            String sLogMsg = "";
            StringBuilder sbLogMsg = new StringBuilder(sLogMsg);

            if (dbRec.getType().equals(Pwdtypes.S_CREDS_TYPE) && (dbRec.getCredId() > 0)) {
                dbRec.setClientId(iClientId);
                dbRec.setCredId(iCredId);
                dbRec.setChallenge(jtxtChlng.getText().toString());
                dbRec.setResponse(l_crypto.encrypt(jtxtRsp.getText().toString()));
                dbRec.setTrack(jcbTrack.getSelectedItem().toString());

                /** Check for changes and insert log if necessary */
                if (!sChallenge.equals(jtxtChlng.getText())) {
                    sbLogMsg.append("Application [" + jtxtApp.getText() + "], Challenge modified, old ["
                            + sChallenge + "], new [" + jtxtChlng.getText() + "]");
                }

                if (!sResponse.equals(jtxtRsp.getText())) {
                    if (sbLogMsg.toString().length() > 0) {
                        sbLogMsg.append(",");
                    } else {
                        sbLogMsg.append("Application [" + jtxtApp.getText() + "],");
                    }
                    sbLogMsg.append("Response modified, old [" + sResponse + "]");
                }

                if (sbLogMsg.toString().length() > 0) {
                    dbRecLog.setType(Pwdtypes.S_LOG_TYPE);
                    dbRecLog.setLog(sbLogMsg.toString());
                    dbRecLog.setModifyDate(sCurDate);
                    if (l_sqliteops.insertRecord(dbRecLog) < 0) {
                        JOptionPane.showMessageDialog(null,
                                "Insert log record failed [" + dbRecLog.getResult() + "]");
                    }
                }

                if (!jcbTrack.getSelectedItem().toString().equals("0")) {
                    iDaysToAdd = Integer.parseInt(jcbTrack.getSelectedItem().toString());

                    calNow.add(Calendar.DATE, iDaysToAdd);
                    sValue = sdf1.format(calNow.getTime());

                    System.out.println("DEBUG->Date (sValue) [" + sValue + "]");
                    dbRec.setModifyDate(sValue);
                }
                /// Update the record
                if (l_sqliteops.updateRecord(dbRec) < 0) {
                    JOptionPane.showMessageDialog(null, "Update record failed [" + dbRec.getResult() + "]");
                } else {
                    int iRow = jtabCreds.getSelectedRow();
                    jtabCreds.setValueAt(jtxtChlng.getText().toString(), iRow, 1);
                    jtabCreds.setValueAt(l_crypto.encrypt(jtxtRsp.getText().toString()), iRow, 2);
                    jtabCreds.setValueAt(jcbTrack.getSelectedItem().toString(), iRow, 3);
                    jtabCreds.setValueAt(sValue, iRow, 4);

                    jtabCreds.setValueAt(sValue, iRow, 4);
                    clearCredsFields();
                    enableCredsButtons();
                }
            }
        }
    });

    /// Button - Delete button for credentials
    btnCredDelete = new JButton("Delete");
    btnCredDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dbRec.setType(Pwdtypes.S_CREDS_TYPE);
            dbRec.setCredId(iCredId);
            dbRec.setChallenge(jtxtChlng.getText().toString());
            dbRec.setResponse(jtxtRsp.getText().toString());
            if (l_sqliteops.deleteRecord(dbRec) < 0) {
                JOptionPane.showMessageDialog(null,
                        "Delete credential record failed [" + dbRec.getResult() + "]");
            } else {
                DefaultTableModel jtabModel = (DefaultTableModel) jtabCreds.getModel();
                jtabModel.removeRow(jtabCreds.getSelectedRow());
                clearCredsFields();
                enableCredsButtons();
            }
        }
    });

    /// Button - Clear button for credentials
    btnCredClear = new JButton("Clear");
    btnCredClear.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            clearCredsFields();
            enableCredsButtons();
        }
    });

    /// End section for credentials challenges/responses - text fields and buttons

    JScrollPane scrollPane_1 = new JScrollPane();
    scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    btnShowAssoc = new JButton("Display Associated Challenges/Responses in new window");

    /// Display the challenges/responses associated to the application in a popup window. 
    /// This is to make it easier to view when all of the values are needed
    btnShowAssoc.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String sTitle = "Credentials for: " + jtxtApp.getText();
            String sDisplay = "";

            sDisplay += "\n";
            DefaultTableModel jTmpModel = (DefaultTableModel) jtabCreds.getModel();
            for (int i = 0; i < jTmpModel.getRowCount(); i++) {
                sDisplay += "Q. " + jTmpModel.getValueAt(i, 1).toString() + "  A. "
                        + l_crypto.decrypt(jTmpModel.getValueAt(i, 2).toString()) + "\n";
            }

            JOptionPane.showMessageDialog(null, sDisplay, sTitle, JOptionPane.INFORMATION_MESSAGE);
        }
    });

    JLabel lblTrackUpdates = new JLabel("Exp Days");

    /// Values for expiration days are hardcoded, may want to move to a table for metadata
    jcbTrack.addItem("0");
    jcbTrack.addItem("30");
    jcbTrack.addItem("45");
    jcbTrack.addItem("60");
    jcbTrack.addItem("90");
    jcbTrack.addItem("180");
    jcbTrack.addItem("365");
    jcbTrack.setSelectedItem("0");

    btnEdit = new JButton("Edit");
    btnEdit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            jtxtChlng.setEnabled(true);
            jtxtRsp.setEnabled(true);
            jcbTrack.setEnabled(true);
            btnCredReplace.setEnabled(true);
            btnCredAdd.setEnabled(true);
        }
    });
    btnEdit.setEnabled(false);

    GroupLayout gl_contentPane = new GroupLayout(contentPane);
    gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane
                    .createParallelGroup(Alignment.LEADING)
                    .addGroup(gl_contentPane.createSequentialGroup().addGap(207)
                            .addComponent(lblThePasswordSaver))
                    .addGroup(gl_contentPane.createSequentialGroup().addGap(23).addGroup(gl_contentPane
                            .createParallelGroup(Alignment.LEADING)
                            .addGroup(gl_contentPane.createSequentialGroup().addComponent(btnAdd)
                                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnReplace)
                                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnDelete)
                                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnSearch)
                                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnClear))
                            .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane
                                    .createParallelGroup(Alignment.LEADING)
                                    .addGroup(gl_contentPane.createSequentialGroup()
                                            .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                    .addComponent(lblUrlapplication)
                                                    .addComponent(lblDescription))
                                            .addPreferredGap(ComponentPlacement.RELATED)
                                            .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                                                    .addComponent(jtxtApp, GroupLayout.PREFERRED_SIZE, 154,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jtxtDesc, GroupLayout.PREFERRED_SIZE, 260,
                                                            GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 355,
                                            GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                                    .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
                                            .addComponent(btnShowAssoc)
                                            .addGroup(gl_contentPane.createSequentialGroup()
                                                    .addGroup(gl_contentPane
                                                            .createParallelGroup(Alignment.TRAILING)
                                                            .addComponent(lblResponse)
                                                            .addComponent(lblChallenge))
                                                    .addGap(18)
                                                    .addGroup(gl_contentPane
                                                            .createParallelGroup(Alignment.LEADING)
                                                            .addGroup(gl_contentPane.createSequentialGroup()
                                                                    .addComponent(jtxtRsp, 272, 272, 272)
                                                                    .addGap(26).addComponent(lblTrackUpdates)
                                                                    .addPreferredGap(
                                                                            ComponentPlacement.UNRELATED)
                                                                    .addComponent(jcbTrack,
                                                                            GroupLayout.PREFERRED_SIZE, 55,
                                                                            GroupLayout.PREFERRED_SIZE))
                                                            .addComponent(jtxtChlng, GroupLayout.PREFERRED_SIZE,
                                                                    440, GroupLayout.PREFERRED_SIZE)))
                                            .addGroup(gl_contentPane
                                                    .createParallelGroup(Alignment.LEADING, false)
                                                    .addGroup(gl_contentPane.createSequentialGroup()
                                                            .addComponent(btnCredAdd,
                                                                    GroupLayout.PREFERRED_SIZE, 78,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addPreferredGap(ComponentPlacement.RELATED)
                                                            .addComponent(btnCredReplace)
                                                            .addPreferredGap(ComponentPlacement.RELATED)
                                                            .addComponent(btnCredDelete,
                                                                    GroupLayout.PREFERRED_SIZE, 75,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addPreferredGap(ComponentPlacement.UNRELATED)
                                                            .addComponent(btnCredClear)
                                                            .addPreferredGap(ComponentPlacement.RELATED,
                                                                    GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                            .addComponent(btnEdit))
                                                    .addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE,
                                                            GroupLayout.DEFAULT_SIZE,
                                                            GroupLayout.PREFERRED_SIZE))))))
                    .addGroup(gl_contentPane.createSequentialGroup().addGap(36).addComponent(chkDelAssoc)))
                    .addContainerGap(57, Short.MAX_VALUE)));
    gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_contentPane.createSequentialGroup().addContainerGap().addComponent(lblThePasswordSaver)
                    .addGap(45)
                    .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
                            .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane
                                    .createParallelGroup(Alignment.BASELINE).addComponent(lblUrlapplication)
                                    .addComponent(jtxtApp, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblChallenge)).addPreferredGap(ComponentPlacement.UNRELATED)
                                    .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                            .addComponent(lblDescription)
                                            .addComponent(jtxtDesc, GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblResponse)))
                            .addGroup(gl_contentPane.createSequentialGroup()
                                    .addComponent(jtxtChlng, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(ComponentPlacement.UNRELATED)
                                    .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                            .addComponent(jtxtRsp, GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblTrackUpdates)
                                            .addComponent(jcbTrack, GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
                    .addGap(18)
                    .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(btnAdd)
                            .addComponent(btnReplace).addComponent(btnDelete).addComponent(btnSearch)
                            .addComponent(btnClear).addComponent(btnCredAdd).addComponent(btnCredReplace)
                            .addComponent(btnCredDelete).addComponent(btnCredClear).addComponent(btnEdit))
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
                            .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                                    .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 208,
                                            GroupLayout.PREFERRED_SIZE)
                                    .addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, 109,
                                            GroupLayout.PREFERRED_SIZE))
                            .addGroup(gl_contentPane.createSequentialGroup().addGap(120)
                                    .addComponent(btnShowAssoc)))
                    .addGap(18).addComponent(chkDelAssoc).addContainerGap(170, Short.MAX_VALUE)));

    /// JTable - Credentials table setup/definition - BEGIN
    jtabCreds = new JTable();
    jtabCreds.setModel(new DefaultTableModel(new Object[][] {},
            new String[] { "ID", "Challenge", "Response", "Exp Days", "Expiration Date" }) {
        Class[] columnTypes = new Class[] { Integer.class, String.class, String.class, String.class,
                String.class };

        public Class getColumnClass(int columnIndex) {
            return columnTypes[columnIndex];
        }
    });
    jtabCreds.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
    scrollPane_1.setViewportView(jtabCreds);
    /// JTable - Credentials table setup/definition - END

    jtabApps = new JTable();
    scrollPane.setViewportView(jtabApps);

    jtabApps.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtabApps.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
    jtabApps.setModel(
            new DefaultTableModel(new Object[][] {}, new String[] { "ID", "URL/Application", "Description" }) {
                Class[] columnTypes = new Class[] { Integer.class, String.class, String.class };

                public Class getColumnClass(int columnIndex) {
                    return columnTypes[columnIndex];
                }

                @Override
                public boolean isCellEditable(int row, int column) {
                    //all cells false
                    return false;
                }
            });
    jtabApps.getColumnModel().getColumn(1).setMinWidth(55);
    jtabApps.getColumnModel().getColumn(2).setMinWidth(55);
    contentPane.setLayout(gl_contentPane);
    contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] { jtxtChlng,
            lblThePasswordSaver, jtxtApp, jtxtDesc, btnAdd, btnReplace, btnDelete, btnSearch, btnClear, jtxtRsp,
            btnCredAdd, btnCredReplace, btnCredDelete, btnCredClear, scrollPane, jtabApps, lblUrlapplication,
            lblDescription, chkDelAssoc, lblChallenge, lblResponse, scrollPane_1, jtabCreds }));
    setFocusTraversalPolicy(new FocusTraversalOnArray(
            new Component[] { menuBar, jtxtApp, jtxtDesc, btnAdd, btnReplace, btnDelete, btnSearch, btnClear,
                    jtxtChlng, jtxtRsp, btnCredAdd, btnCredReplace, btnCredDelete, btnCredClear, contentPane,
                    mnFile, mntmExit, lblThePasswordSaver, scrollPane, jtabApps, lblUrlapplication,
                    lblDescription, chkDelAssoc, lblChallenge, lblResponse, scrollPane_1, jtabCreds }));

    /// Initial data load
    dbRec = new DbRecord();
    dbRec.setType(Pwdtypes.S_CLIENT_TYPE);
    dbRec.setClientName("");
    dbRec.setClientDesc("");
    loadTable(dbRec);
    disableCredsButtons();

    ListSelectionModel rowSM = jtabApps.getSelectionModel();

    //Listener for client row change;
    rowSM.addListSelectionListener(new ListSelectionListener() {

        /// Fill the form values when a row is selected in the JTable
        @Override
        public void valueChanged(ListSelectionEvent e) {
            ListSelectionModel lsmData = (ListSelectionModel) e.getSource();
            if (!lsmData.isSelectionEmpty()) {
                int iRow = lsmData.getMinSelectionIndex();
                iClientId = Integer.parseInt(jtabApps.getValueAt(iRow, 0).toString());
                jtxtApp.setText(jtabApps.getValueAt(iRow, 1).toString());
                jtxtDesc.setText(jtabApps.getValueAt(iRow, 2).toString());

                dbRec.setType(Pwdtypes.S_CREDS_TYPE);
                dbRec.setClientId(iClientId);
                loadTable(dbRec);
                enableButtons();
                clearCredsFields();
                enableCredsButtons();
            }
        }
    });

    ListSelectionModel rowCred = jtabCreds.getSelectionModel();

    //Listener for credential row change;
    rowCred.addListSelectionListener(new ListSelectionListener() {

        /// Fill the form values when a row is selected in the JTable
        @Override
        public void valueChanged(ListSelectionEvent e) {
            ListSelectionModel lsmData = (ListSelectionModel) e.getSource();
            if (!lsmData.isSelectionEmpty()) {
                int iRow = lsmData.getMinSelectionIndex();
                iCredId = Integer.parseInt(jtabCreds.getValueAt(iRow, 0).toString());
                jtxtChlng.setText(jtabCreds.getValueAt(iRow, 1).toString());
                jtxtRsp.setText(l_crypto.decrypt(jtabCreds.getValueAt(iRow, 2).toString()));
                jcbTrack.setSelectedItem(jtabCreds.getValueAt(iRow, 3).toString());
                if (null == jtabCreds.getValueAt(iRow, 4)) {
                    sDateModified = "";
                } else {
                    sDateModified = jtabCreds.getValueAt(iRow, 4).toString();
                }
                sChallenge = jtxtChlng.getText();
                sResponse = jtxtRsp.getText();
                dbRec.setType(Pwdtypes.S_CREDS_TYPE);
                dbRec.setCredId(iClientId);
                jtxtChlng.setEnabled(false);
                jtxtRsp.setEnabled(false);
                jcbTrack.setEnabled(false);
                btnEdit.setEnabled(true);
                btnCredDelete.setEnabled(true);
                btnCredClear.setEnabled(true);
            }
        }
    });

}

From source file:phenoviewer.ReNameJFrame.java

private DefaultTableModel clearTable(DefaultTableModel d) {
    // clear the tabel
    int numrows = d.getRowCount();
    for (int i = numrows - 1; i >= 0; i--) {
        d.removeRow(i);
    }/* w  ww  .  j  av a 2s.  c o  m*/
    return d;
}

From source file:pkgnew.line.PluginDialog.java

private void listPlugins() {
    DefaultTableModel model = (DefaultTableModel) TablePlugins.getModel();
    PluginManager pluginManager = PluginManager.getInstance();
    List<Plugin> plugins = pluginManager.getPlugins();
    //clear out the table
    for (int i = 0; i < model.getRowCount(); i++) {
        model.removeRow(i);
    }// w  w w .ja  v a  2 s.co m
    //update the table
    for (Iterator<Plugin> pluginIterator = plugins.iterator(); pluginIterator.hasNext();) {
        Plugin plugin = (Plugin) pluginIterator.next();
        model.addRow(new Object[] { false, plugin.getName(), plugin.isEnabled() });
    }
}

From source file:proyecto4.Principal.java

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    // TODO add your handling code here:
    DefaultTableModel modelo1 = (DefaultTableModel) jt_agre_ingre.getModel();
    for (int i = 0; i < modelo1.getRowCount(); i++) {
        modelo1.removeRow(i);
    }/*  w  w w.  j av  a  2  s .c om*/
    for (int i = 0; i < lista_ingredientes.size(); i++) {
        modelo1.addRow(new Object[] { false, lista_ingredientes.get(i).toString() });
    }
    jd_agregar_producto.setModal(true);
    jd_agregar_producto.pack();
    jd_agregar_producto.setVisible(true);

}

From source file:proyecto4.Principal.java

private void btn_agregar_prod_a_lista_esperaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_agregar_prod_a_lista_esperaMouseClicked
    // TODO add your handling code here:
    try {/*from  w ww .ja  v  a 2  s. com*/
        System.out.println(lista_ingredientes.toString());
        String nom = txt_nom_prod.getText();
        int time = Integer.parseInt(txt_tiempo_prep.getText());
        double precio = Double.parseDouble(txt_prec_prod.getText());
        DefaultTableModel modelo = (DefaultTableModel) jt_agre_ingre.getModel();
        ArrayList temp = new ArrayList();
        for (int i = 0; i < modelo.getRowCount(); i++) {
            temp.add((jt_agre_ingre.getValueAt(i, 1).toString()));
        }
        lista_ordenes_espera.add(new Producto_O_Orden(nom, precio, time, temp));
        JOptionPane.showMessageDialog(this, "Producto ah sido agregado");
        for (int i = 0; i < lista_ordenes_espera.size(); i++) {
            for (int j = 0; j < lista_ingredientes.size(); j++) {
                if (lista_ordenes_espera.get(i).getLista().toString()
                        .contains(lista_ingredientes.get(j).getNombre())) {
                    lista_ingredientes.remove(lista_ingredientes.get(j));
                }
            }
        }
        DefaultTableModel modelo1 = (DefaultTableModel) jt_agre_ingre.getModel();
        for (int i = 0; i < modelo1.getRowCount(); i++) {
            modelo1.removeRow(i);
        }
        System.out.println(lista_ingredientes.toString());

        txt_nom_prod.setText("");
        txt_prec_prod.setText("");
        txt_tiempo_prep.setText("");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "No ah sido agregado");
    }

}

From source file:proyecto4.Principal.java

private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
    // TODO add your handling code here:        
    DefaultTableModel modelo1 = (DefaultTableModel) jt_ordenes_camiones.getModel();
    for (int i = 0; i < modelo1.getRowCount(); i++) {
        modelo1.removeRow(i);
    }/*w w  w. j ava  2  s  .  c o m*/
    for (int i = 0; i < lista_ordenes_cocineros.size(); i++) {
        modelo1.addRow(new Object[] { false, lista_ordenes_cocineros.get(i).getNombre().toString() });
    }
    jd_camiones.setModal(true);
    jd_camiones.pack();
    jd_camiones.setVisible(true);
}