Example usage for javax.swing.table DefaultTableModel addRow

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

Introduction

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

Prototype

public void addRow(Object[] rowData) 

Source Link

Document

Adds a row to the end of the model.

Usage

From source file:Vista.VentasCliente.java

private void jButton_executeGeneralVClActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_executeGeneralVClActionPerformed
    String[] nombres = { "Nombre", "Numero de Contacto", "Empresa", "Numero de facturas" };

    String[] filasT = client.consultaGeneralCliente("0;0", "").split("\\n");

    DefaultTableModel dtm = new DefaultTableModel(nombres, filasT.length);
    dtm = (DefaultTableModel) this.jTable_ConsultaGeneralCliente.getModel();
    this.jTable_ConsultaGeneralCliente.removeAll();

    for (String s : filasT) {
        String[] columnasT = s.split("\\t");
        dtm.addRow(new Object[] { columnasT[1], columnasT[2], columnasT[3], columnasT[4] });
    }//from w  ww. java2s.  c  om
}

From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java

public synchronized void setCurrentTPS(long time, int index, double tps) {
    synchronized (LiveMonitorInfo.LOCK) {
        DefaultTableModel model = (DefaultTableModel) monitorTable.getModel();
        if (model.getRowCount() <= 2 + (index * ROW_PER_TX_TYPE)) {
            model.addRow(new Object[] { "", "" });
        }// w ww  . j  a v a2  s . co  m
        model.setValueAt(String.format("%.1f", tps), 2 + (index * ROW_PER_TX_TYPE), 1);
        if (numTransactionType < index + 1) {
            String newName = "Type " + (index + 1);
            transactionNames.add(newName);
            numTransactionType = index + 1;

            JLabel newLabel = new JLabel(newName);
            JButton renameButton = new JButton("Rename");
            JButton viewSampleButton = new JButton("View Examples");
            //            JButton enableDisableButton;
            //            if (DBSeerGUI.liveDataset.isTransactionEnabled(index))
            //            {
            //               enableDisableButton = new JButton("Disable");
            //            }
            //            else
            //            {
            //               enableDisableButton = new JButton("Enable");
            //            }

            renameButton.addActionListener(this);
            viewSampleButton.addActionListener(this);
            //            enableDisableButton.addActionListener(this);

            transactionTypesPanel.add(newLabel);
            transactionTypesPanel.add(renameButton);
            transactionTypesPanel.add(viewSampleButton);
            //            transactionTypesPanel.add(enableDisableButton);

            transactionLabels.add(newLabel);
            transactionRenameButtons.add(renameButton);
            transactionViewSampleButtons.add(viewSampleButton);
            //            transactionEnableDisableButtons.add(enableDisableButton);

            for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) {
                dataset.addTransactionType("Type " + numTransactionType);
            }

            //         TimeSeriesCollection newThroughputCollection = new TimeSeriesCollection(new TimeSeries(newName, Millisecond.class));
            //         TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset();
            throughputCollection.addSeries(new TimeSeries(newName, Millisecond.class));
            latencyCollection.addSeries(new TimeSeries(newName, Millisecond.class));

            //         throughputChartPanel.getChart().getXYPlot().setDataset(index, newThroughputCollection);

            this.revalidate();
            this.repaint();
        }
        model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(index)),
                2 + (index * ROW_PER_TX_TYPE), 0);

        //      TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset();
        if (index < throughputCollection.getSeriesCount()) {
            TimeSeries series = throughputCollection.getSeries(index);
            //            series.add(new Millisecond(), tps);
            series.addOrUpdate(new Millisecond(new Date(time * 1000)), tps);
        }
    }
}

From source file:GUI.MainJF.java

public void LlenarTabla() {
    String[] columnNames = { "ID", "Nombre", "Email", "Edad", "Tipo", "", "" };
    Object[][] data = null;/*from  w ww . j  a  va  2 s  .co m*/
    DefaultTableModel model = new DefaultTableModel(data, columnNames);

    HttpResponse response;
    response = JSON.request(Config.URL + "usuarios/listar.json");
    JSONObject jObject = JSON.JSON(response);
    try {
        JSONArray jsonArr = jObject.getJSONArray("data");

        for (int i = 0; i < jsonArr.length(); i++) {
            JSONObject data_json = jsonArr.getJSONObject(i);
            model.addRow(
                    new Object[] { data_json.get("idUsuario").toString(), data_json.get("nombre").toString(),
                            data_json.get("email").toString(), data_json.get("edad").toString(),
                            data_json.get("descripcion").toString(), "Editar", "Eliminar" });
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    tb_usuarios.setModel(model);

    Action editar = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {

            JTable table = (JTable) e.getSource();
            int modelRow = Integer.valueOf(e.getActionCommand());

            String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0);
            String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1);
            String email = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 2);
            String edad = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 3);
            String tipo = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 4);

            FormUsuarios U = new FormUsuarios();

            U.setID(id);
            U.setNombre(nombre);
            U.setEmail(email);
            U.setEdad(edad);
            U.setTipo(tipo);

            U.setLocationRelativeTo(null);
            U.setVisible(true);
        }
    };
    ButtonColumn botonEditar = new ButtonColumn(tb_usuarios, editar, 5);
    botonEditar.setMnemonic(KeyEvent.VK_D);

    Action eliminar = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JTable table = (JTable) e.getSource();
            int modelRow = Integer.valueOf(e.getActionCommand());
            String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0);
            String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1);

            int rs = JOptionPane.showConfirmDialog(null,
                    "Estas seguro que deseas eliminas el usuario: " + nombre + " ?", "Eliminar",
                    JOptionPane.YES_NO_OPTION);
            if (rs == JOptionPane.YES_OPTION) {

                List<NameValuePair> parametros = new ArrayList<NameValuePair>();
                parametros.add(new BasicNameValuePair("idUsuario", id));

                HttpResponse response = JSON.request(Config.URL + "usuarios/eliminar.json", parametros);
                JSONObject jObject = JSON.JSON(response);
                int code = Integer.parseInt(jObject.get("code").toString());

                /*if(code == 201){
                JOptionPane.showMessageDialog(null, "Usuario eliminado");
                //((DefaultTableModel)table.getModel()).removeRow(modelRow);
                }else{
                JOptionPane.showMessageDialog(null, "Error eliminar Usuario");
                }*/
            }

        }
    };
    ButtonColumn botonEliminar = new ButtonColumn(tb_usuarios, eliminar, 6);
    botonEliminar.setMnemonic(KeyEvent.VK_D);
    model.fireTableDataChanged();

}

From source file:com.jtk.pengelolaanujian.controller.panitiaController.PrintSoalController.java

public List<StorageSoal> searchSoalStorage(String kodeSoal, JTable jTable) {
    StorageSoalFacade storageSoalFacade = new StorageSoalFacade();
    StafFacade stafFacade = new StafFacade();
    List<StorageSoal> storageSoals = storageSoalFacade.findByKodeSoal(kodeSoal);
    Object[] columnsName = { "Nama File", "Tanggal Upload", "Uploader" };

    DefaultTableModel dtm = new DefaultTableModel(null, columnsName) {
        @Override/*from w w w.  j ava2  s . c  o m*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
    for (StorageSoal soal : storageSoals) {
        Object[] o = new Object[4];
        o[0] = soal.getNamaFile();
        o[1] = sdf.format(soal.getStsoalTglUpload());
        o[2] = stafFacade.findByStafNip(soal.getStafNip()).getStafNama();

        dtm.addRow(o);
    }
    jTable.setModel(dtm);

    return storageSoals;
}

From source file:Vista.VentasCliente.java

private void jButton_executeSpecificVCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_executeSpecificVCActionPerformed
    // TODO add your handling code here:
    String[] respuesta = client.consultaGeneralCliente("0;" + jTextField_NombreCliente.getText(), "")
            .split(";");
    String[] nombres = { "Nombre", "Numero de Contacto", "Empresa", "Numero de facturas" };
    DefaultTableModel dtm = new DefaultTableModel(nombres, respuesta.length);
    dtm = (DefaultTableModel) this.jTable_ConsultaParticularlCliente.getModel();
    this.jTable_ConsultaGeneralCliente.removeAll();

    for (String s : respuesta) {
        String[] columnasT = s.split("\\t");
        dtm.addRow(new Object[] { columnasT[1], columnasT[2], columnasT[3], columnasT[4] });
    }/*from w  w w .  java  2 s  .c  o  m*/

}

From source file:Vista.VentasCliente.java

private void jButton_executeGeneralVCl_CiudadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_executeGeneralVCl_CiudadActionPerformed

    String[] respuesta = client//from w w w .j  a  va 2s  .  c o  m
            .consultaGeneralCliente("0;" + jTextField_NombreCliente.getText(), jTextField_City.getText().trim())
            .split(";");
    String[] nombres = { "Nombre", "Numero de Contacto", "Empresa", "Numero de facturas" };
    DefaultTableModel dtm = new DefaultTableModel(nombres, respuesta.length);
    dtm = (DefaultTableModel) this.jTable_ConsultaParticularlCliente.getModel();
    this.jTable_ConsultaGeneralCliente.removeAll();

    for (String s : respuesta) {
        String[] columnasT = s.split("\\t");
        dtm.addRow(new Object[] { columnasT[1], columnasT[2], columnasT[3], columnasT[4] });
    }

}

From source file:GUI.VentanaPrincipal.java

public void addtablespaceInfoToTable() {
    String[] filas = Conector.conectorBD.getInfoTableSpaces().split("\n");
    String[] columnas;//from   ww w . j a  v a2 s.c  om
    DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
    for (String fila : filas) {
        columnas = fila.split(",");
        //                          tablespace+","+usado+","+libre+","+total+","+%libre+"\n";
        modelo.addRow(
                new Object[] { columnas[0], columnas[1], columnas[2], columnas[3], columnas[4], null, null });//columnas[2],columnas[3]});
    }

}

From source file:view.ViewReportUI.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.//from  w w w .j a va 2 s  .  c o m
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    jTable1 = new javax.swing.JTable();
    jButton1 = new javax.swing.JButton();
    jPanel1 = new javax.swing.JPanel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle(" Expense Report");
    setResizable(false);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    String col[] = { "Amount", "Store", "Date of Purchase", "Date Addded" };
    DefaultTableModel tableModel = new DefaultTableModel(col, 0) {
        public boolean isCellEditable(int row, int column) {
            return false;//This causes all cells to be not editable
        }
    };
    jTable1.setModel(tableModel);
    for (model.InvoiceModel in : myInvoice) {

        Object[] objs = { "$" + in.getAmount(), in.getStore(), in.getDateOfPurchase(), in.getAddedDate() };
        tableModel.addRow(objs);
    }

    jTable1.setGridColor(Color.gray);
    jTable1.getTableHeader().setBackground(new Color(102, 178, 255));
    jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jTable1MouseClicked(evt);
        }
    });
    jScrollPane1.setViewportView(jTable1);

    jButton1.setText("Close");

    jPanel1.setLayout(new java.awt.BorderLayout());
    PieDataset dataset = createDataset();
    // based on the dataset we create the chart
    JFreeChart chart = createChart(dataset, "Hello");
    // we put the chart into a panel
    this.chartPanel = new ChartPanel(chart);
    // default size
    chartPanel.setPreferredSize(new Dimension(500, 270));
    //        this.jPanel1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    //
    System.out.println(chartPanel == null);
    jPanel1.add(chartPanel);
    jPanel1.validate();

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                    layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1).addGap(242, 242, 242))
            .addGroup(layout.createSequentialGroup().addGap(15, 15, 15)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 536,
                                    Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap(14, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 293,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton1)
                    .addGap(20, 20, 20)));

    pack();
    setLocationRelativeTo(null);
}

From source file:front.TestTable.java

public TestTable(Controller cont, int[][] response, float[] vec, float rango, int cantIntervalos) {

    controller = cont;/* w  ww .  j a v  a2 s  . c o m*/
    contador = response.length;
    initComponents();

    DecimalFormat in = new DecimalFormat("0.00");
    DecimalFormat aleat = new DecimalFormat("0.0000");
    DecimalFormat c = new DecimalFormat("0.000");
    int contador = 0;
    int frecEsp = (int) vec.length / cantIntervalos;
    double rangoM;
    float[][] matrizIntervalos = new float[cantIntervalos][2];
    double[] estadisticoParcial = new double[cantIntervalos];
    DefaultTableModel tm = (DefaultTableModel) table.getModel();

    for (int i = 0; i < response.length; i++) {
        if (i == 0) {
            rangoM = rango;
            tm.addRow(new Object[] { "0.00 - " + in.format(rangoM), i, response[i][1], frecEsp,
                    c.format(estadisticoPrueba(response, frecEsp, i)) });
            contador++;
            matrizIntervalos[0][0] = 0;
            matrizIntervalos[0][1] = (float) rangoM;

        } else {
            if (contador == 1) {
                tm.addRow(new Object[] { in.format(rango) + " - " + in.format(rango + rango), i, response[i][1],
                        frecEsp, c.format(estadisticoPrueba(response, frecEsp, i)) });

                matrizIntervalos[i][0] = rango;
                matrizIntervalos[i][1] = (float) rango + rango;
                contador++;

            } else {
                tm.addRow(new Object[] {
                        in.format(rango * contador) + " - " + in.format((rango * contador) + rango), i,
                        response[i][1], frecEsp, c.format(estadisticoPrueba(response, frecEsp, i)) });
                matrizIntervalos[i][0] = rango * contador;
                matrizIntervalos[i][1] = (rango * contador) + rango;
                contador++;
            }

        }
    }

    if (frecEsp < 5) {
        DefaultTableModel tm2 = (DefaultTableModel) tablaFe.getModel();
        double estadisticoTotal = 0;
        int frecEspAcumulada = 0;
        int frecObsAcumulada = 0;
        int inicio = 0;
        float a = 0;

        for (int i = 0; i < tm.getRowCount(); i++) {
            frecEspAcumulada += (int) tm.getValueAt(i, 2);
            frecObsAcumulada += (int) tm.getValueAt(i, 1);

            if (frecEspAcumulada >= 5) {
                estadisticoParcial[i] += estadisticoPrueba2(frecObsAcumulada, (int) frecEspAcumulada);
                tm2.addRow(new Object[] {
                        in.format(matrizIntervalos[inicio][0]) + " - " + in.format(matrizIntervalos[i][1]),
                        (int) frecObsAcumulada, frecEspAcumulada, c.format(estadisticoParcial[i]) });
                a = matrizIntervalos[inicio][0];
                inicio = i + 1;

                frecEspAcumulada = 0;
                frecObsAcumulada = 0;
            } else {
                if (i == tm.getRowCount() - 1) {
                    int filaAUnir = tm2.getRowCount() - 1;
                    //actualizo intervalo
                    tm2.setValueAt(in.format(a) + " - " + in.format(matrizIntervalos[i][1]), filaAUnir, 0);
                    //frec observada
                    tm2.setValueAt(frecObsAcumulada + (int) tm2.getValueAt(filaAUnir, 1), filaAUnir, 1);
                    //frec esperada
                    tm2.setValueAt(frecEspAcumulada + (int) tm2.getValueAt(filaAUnir, 2), filaAUnir, 2);

                    int frecObsUltima = (int) tm2.getValueAt(filaAUnir, 1);
                    int frecEspUltima = (int) tm2.getValueAt(filaAUnir, 2);

                    estadisticoParcial[i - 1] = estadisticoPrueba2(frecObsUltima, frecEspUltima);
                    tm2.setValueAt(estadisticoParcial[i - 1], filaAUnir, 3);
                    break;
                }
            }
        }

        for (int i = 0; i < estadisticoParcial.length; i++) {
            estadisticoTotal += estadisticoParcial[i];
        }
        txt_gradosNuevo.setText("" + gradosLibertad(tm2.getRowCount()));
        txt_estadisticoNuevo.setText("" + c.format(estadisticoTotal));
    }
    //para mostrar los valores generados
    String acum = "";
    for (int i = 0; i < vec.length; i++) {
        acum += "Valor " + (i + 1) + ": " + aleat.format(vec[i]) + ".\n";
    }
    txt_valoresGenerados.setText(acum);

    //para el calculo de mi estadistico de prueba total
    txt_estadistico.setText("" + c.format(estadisticoPruebaTotal(response, frecEsp)));
    txt_grados.setText("" + gradosLibertad(cantIntervalos));

    valoresGenerados = vec;
    this.cantIntervalos = cantIntervalos;
    agregarHistograma();

}

From source file:com.alvermont.terraj.stargen.ui.KeyDialog.java

/**
 * Add an entry to the key /*  w w w .j  a va  2  s .  c om*/
 *
 * @param type The type of the planet
 * @param description The description of the planet
 */
protected void addKeyEntry(PlanetType type, String description) {
    DefaultTableModel dtm = (DefaultTableModel) keyTable.getModel();

    Object[] row = new Object[3];

    try {
        BufferedImage image = UIUtils.getImage(type.getPrintText());

        image = UIUtils.scaleImage(image, 32, 32);

        Icon icon = new ImageIcon(image);

        row[0] = icon;
        row[1] = type.getPrintText();
        row[2] = description;

        dtm.addRow(row);
    } catch (IOException ioe) {
        log.error("IOException getting icons for key", ioe);
    }
}