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:aasdntool.AASDNTool.java

private void openFlowSwitchesActionPerformed(java.awt.event.ActionEvent evt) {

    StringBuffer response = new StringBuffer();

    try {//from w  w  w  .j a va  2  s.co m
        URL obj = new URL("http://" + controllerIP + ":8080/wm/core/controller/switches/json");
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        // optional default is GET
        con.setRequestMethod("GET");

        int responseCode = con.getResponseCode();
        System.out.println("\nSending 'GET' request to URL : " + "http://" + controllerIP
                + ":8080/wm/core/controller/switches/json");
        System.out.println("Response Code : " + responseCode);

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        ObjectMapper mapper = new ObjectMapper();
        List<Switches> switchList = mapper.readValue(response.toString(),
                mapper.getTypeFactory().constructCollectionType(List.class, Switches.class));

        DefaultTableModel dtm = new DefaultTableModel(0, 0);

        // add header of the table
        String header[] = new String[] { "Switch DPID", "IP Address" };

        // add header in table model
        dtm.setColumnIdentifiers(header);
        switchTable.setModel(dtm);

        // add row dynamically into the table
        for (Switches sw : switchList) {
            dtm.addRow(new Object[] { sw.getDpid(), sw.getInetAddress() });
        }

    } catch (Exception e) {
        System.out.println("Exception Occured:" + e);
    }
}

From source file:graph.plotter.LineGraph.java

/**
 * This method works for adding new data entry
 * @param evt /*from  w w w .j a v a  2  s . c o  m*/
 */
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here
    DefaultTableModel model = (DefaultTableModel) Table.getModel();
    model.addRow(new Object[] { jTextField2.getText(), jTextField3.getText() });
    cnt++;

}

From source file:UserInterface.DonorRole.DonorRecordsJPanel.java

public void populateTable() {
    DefaultTableModel dtm = (DefaultTableModel) donorHormoneLevelsJTbl.getModel();
    dtm.setRowCount(0);//from   w w  w  .  j a va 2  s. c  o  m
    for (Employee donor : organization.getEmployeeDirectory().getEmployeeList()) {
        if (donor.getName().equalsIgnoreCase(userAccount.getEmployee().getName())) {
            for (HormonalRecords hr : donor.getHormonalRecordsHistory().getHormonalRecordsList()) {
                Object row[] = new Object[5];
                row[0] = hr;
                row[1] = hr.getLeutinizingHormoneLevels();
                row[2] = hr.getFollicleStimulatingHormoneLevels();
                row[3] = hr.gethCGLevels();
                row[4] = hr.getTempDropIOT();
                dtm.addRow(row);

            }

        }
    }

}

From source file:generadorqr.jifrGestionArticulos.java

public static DefaultTableModel LlenarTablaArticulos() {
    try {//  w  w w .j a va2s.c  o  m
        String titulos[] = { "ID", "CATEGORIA", "NOMBRE", "CANTIDAD", "DESCRIPCION", "IMG 1", "IMG 2", "IMG 3",
                "SONIDO", "VIDEO", "IMAGEN QR" };
        String SQLTA = "SELECT a.IDARTICULO, c.NOMBRECATEGORIA, a.NOMBREARTICULO,a.CANTIDADARTICULO, a.DESCRIPCIONARTICULO, a.IMAGENUNOARTICULO, a.IMAGENDOSARTICULO, a.IMAGENTRESARTICULO, a.SONIDOARTICULO, a.VIDEOARTICULO, a.IMAGENQRARTICULO FROM articulos AS a INNER JOIN categorias AS c USING(IDCATEGORIA) ORDER BY a.IDARTICULO, c.NOMBRECATEGORIA, a.NOMBREARTICULO ASC";
        DefaultTableModel model = new DefaultTableModel(null, titulos);
        Statement sent = conn.createStatement();
        ResultSet rs = sent.executeQuery(SQLTA);
        String[] fila = new String[11];
        while (rs.next()) {
            fila[0] = rs.getString("IDARTICULO");
            fila[1] = rs.getString("NOMBRECATEGORIA");
            fila[2] = rs.getString("NOMBREARTICULO");
            fila[3] = rs.getString("CANTIDADARTICULO");
            fila[4] = rs.getString("DESCRIPCIONARTICULO");
            fila[5] = rs.getString("IMAGENUNOARTICULO");
            fila[6] = rs.getString("IMAGENDOSARTICULO");
            fila[7] = rs.getString("IMAGENTRESARTICULO");
            fila[8] = rs.getString("SONIDOARTICULO");
            fila[9] = rs.getString("VIDEOARTICULO");
            fila[10] = rs.getString("IMAGENQRARTICULO");
            model.addRow(fila);
        }
        return model;
    } catch (Exception e) {
        return null;
    }
}

From source file:generadorqr.jifrGestionArticulos.java

public static DefaultTableModel LlenarTablaArticulosporCategora() {
    try {/*from w  w  w  .j av  a  2  s  .c  o m*/
        String titulos[] = { "ID", "CATEGORIA", "NOMBRE", "CANTIDAD", "DESCRIPCION", "IMG 1", "IMG 2", "IMG 3",
                "SONIDO", "VIDEO", "IMAGEN QR" };
        String SQLTA = "SELECT a.IDARTICULO, c.NOMBRECATEGORIA, a.NOMBREARTICULO,a.CANTIDADARTICULO, a.DESCRIPCIONARTICULO, a.IMAGENUNOARTICULO, a.IMAGENDOSARTICULO, a.IMAGENTRESARTICULO, a.SONIDOARTICULO, a.VIDEOARTICULO, a.IMAGENQRARTICULO FROM articulos AS a INNER JOIN categorias AS c USING(IDCATEGORIA) WHERE c.IDCATEGORIA = "
                + ItemSeleccionado.idCategoria + " ORDER BY a.IDARTICULO ASC";
        DefaultTableModel model = new DefaultTableModel(null, titulos);
        Statement sent = conn.createStatement();
        ResultSet rs = sent.executeQuery(SQLTA);
        String[] fila = new String[11];
        while (rs.next()) {
            fila[0] = rs.getString("IDARTICULO");
            fila[1] = rs.getString("NOMBRECATEGORIA");
            fila[2] = rs.getString("NOMBREARTICULO");
            fila[3] = rs.getString("CANTIDADARTICULO");
            fila[4] = rs.getString("DESCRIPCIONARTICULO");
            fila[5] = rs.getString("IMAGENUNOARTICULO");
            fila[6] = rs.getString("IMAGENDOSARTICULO");
            fila[7] = rs.getString("IMAGENTRESARTICULO");
            fila[8] = rs.getString("SONIDOARTICULO");
            fila[9] = rs.getString("VIDEOARTICULO");
            fila[10] = rs.getString("IMAGENQRARTICULO");
            model.addRow(fila);
        }
        return model;
    } catch (Exception e) {
        return null;
    }
}

From source file:stockit.ClientFrame.java

private void setUpTable() {
    try {// w  w w . ja v a 2s  .c  om
        DBConnection dbcon = new DBConnection();
        dbcon.establishConnection();
        Statement stmt = dbcon.con.createStatement();
        ResultSet rs = stmt.executeQuery(
                "SELECT stock.stockID, company.Name, stock_sector.Sector, stock_daily_performance.Currency, stock_daily_performance.High, stock_daily_performance.Low, stock_daily_performance.Closing_Price, has_positions.Qty, (stock_daily_performance.Opening_Price - stock_daily_performance.Closing_Price) AS Today_Change, ((stock_daily_performance.Opening_Price - stock_daily_performance.Closing_Price) * has_positions.Qty) AS Profit\n"
                        + "FROM stock, stock_sector, stock_daily_performance, has_positions, account, company, client\n"
                        + "WHERE client.Name = '" + name + "'"
                        + "AND client.Client_SSN = account.Client_SSN AND account.Account_ID = has_positions.Account_ID AND stock_daily_performance.StockID = has_positions.Stock_ID AND stock.StockID = has_positions.Stock_ID AND stock_sector.StockID = has_positions.Stock_ID AND company.StockID = stock.StockID AND Date IN\n"
                        + "( Select * from \n" + "(\n" + "SELECT max(Date) \n"
                        + "FROM stock_daily_performance, stock\n"
                        + "where stock_daily_performance.StockID=stock.StockID\n" + "group by stock.StockID\n"
                        + "ORDER BY Date\n" + ") temp_table)");
        DefaultTableModel model = (DefaultTableModel) StockInfoTable.getModel();
        model.setRowCount(0);
        while (rs.next()) {
            //System.out.println(rs.getString("stockID") + "\t" + rs.getString("StockName") + "\t" + rs.getString("Sector") + "\t" + rs.getString("Currency") + "\t" + rs.getString("Closing_Price") + "\t" + rs.getString("Qty") + rs.getString("Today_Change"));
            model.addRow(new Object[] { rs.getString("stockID"), rs.getString("Name"), rs.getString("Sector"),
                    rs.getString("Qty"), rs.getString("High"), rs.getString("Low"),
                    rs.getString("Closing_Price"), rs.getString("Today_Change"), rs.getString("Currency"),
                    rs.getString("Profit") });
        }
        dbcon.con.close();
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}

From source file:UserInterface.Supplier.SalesOverviewJPanel.java

public void populateTable() {
    DefaultTableModel dtm = (DefaultTableModel) performanceJTable.getModel();
    dtm.setRowCount(0);/*from w w w  .  j  av a2 s .  c om*/
    Object[] obj = new Object[3];
    ArrayList<String> temp = new ArrayList<>();
    for (Order o : moc.getMoc()) {
        if (o.getSupplier().getCompanyName().equals(s.getCompanyName())) {
            for (OrderItem oi : o.getListOfItemsOrdered()) {
                if (!temp.contains(oi.getProduct().getTypeOfDevice())) {
                    obj[0] = oi.getProduct().getTypeOfDevice();
                    obj[1] = oi.getQuantity();
                    obj[2] = oi.getProduct().getCost() * oi.getQuantity();
                    dtm.addRow(obj);
                    temp.add(oi.getProduct().getTypeOfDevice());
                } else if (temp.contains(oi.getProduct().getTypeOfDevice())) {
                    for (int i = 0; i < dtm.getRowCount(); i++) {
                        String prodname = (String) dtm.getValueAt(i, 0);
                        if (prodname.equals(oi.getProduct().getTypeOfDevice())) {
                            int q = (int) dtm.getValueAt(i, 1) + oi.getQuantity();
                            int sale = q * oi.getProduct().getCost();
                            dtm.setValueAt(q, i, 1);
                            dtm.setValueAt(sale, i, 2);

                        }

                    }
                }
            }
        }
    }

}

From source file:UserInterface.ViewPersonDetails.java

public void populateTable() {
    DefaultTableModel dtm = (DefaultTableModel) tblvitalSign.getModel();
    dtm.setRowCount(0);/*from w  w w.  ja va2s.  co m*/
    for (VitalSign s : p.getPatient().getVitalsignHistory().getVitalSignHistory()) {
        Object row[] = new Object[6];
        row[0] = s;
        row[1] = s.getRespiratoryrate();
        row[2] = s.getHeartrate();
        row[3] = s.getBloodpressure();
        row[4] = s.getWeight();

        row[5] = s.getStatus();

        dtm.addRow(row);
    }
}

From source file:com.stanley.captioner.MainFrame.java

private void addButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed
{//GEN-HEADEREND:event_addButtonActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(true);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("MP4 VIDEOS", "mp4", "mpeg");
    fileChooser.setFileFilter(filter);//from  w  ww  .j  a v a2s .co  m
    if (lastAddDirectory != null) {
        fileChooser.setCurrentDirectory(lastAddDirectory);
    }
    int returnValue = fileChooser.showOpenDialog(this);

    if (returnValue == JFileChooser.APPROVE_OPTION) {
        lastAddDirectory = fileChooser.getCurrentDirectory();

        DefaultTableModel model = (DefaultTableModel) videoTable.getModel();
        File files[] = fileChooser.getSelectedFiles();
        for (File file : files) {
            boolean alreadyExists = false;
            for (int i = model.getRowCount() - 1; i >= 0; i--) {
                String path = (String) model.getValueAt(i, 0);
                if (file.getAbsolutePath().equals(path)) {
                    alreadyExists = true;
                }
            }

            if (!alreadyExists) {
                model.addRow(getVideoInfo(file));
            }
        }
    }
}

From source file:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java

private void phaseDetection() {
    final class Phase {
        int start;
        int end;/* w ww . j a va2  s .  co  m*/
        CHDistribution dist;
        double bound;

        public Phase(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    double coverage = Double.parseDouble(txtPhasesCoverage.getText());
    int wsize = Integer.parseInt(txtPhasesWSize.getText());

    CHDistribution[] dists = trace.getPhases(coverage, wsize);
    CHDistribution curDist = null;
    CHDistribution lastDist = null;
    int iPhaseBegin, iPhaseEnd;
    Phase p = null;

    DefaultTableModel model = (DefaultTableModel) tablePhases.getModel();
    while (model.getRowCount() > 0) {
        model.removeRow(0);
    }

    if (wsize > 1) {
        // ignore initial window
        model.addRow(new Object[] { 1, (wsize - 1), "{undefined}", "" });
    }

    iPhaseBegin = 0;
    iPhaseEnd = 0;
    curDist = dists[0];
    for (int i = 1; i < dists.length; i++) {
        lastDist = curDist;
        curDist = dists[i];
        if (!curDist.equals(lastDist)) {
            // distribution is different from the previous: phase change
            p = new Phase(iPhaseBegin, iPhaseEnd + (wsize - 1));
            p.dist = lastDist;
            p.bound = trace.getSubTrace(p.start, p.end).getBound(coverage);

            iPhaseBegin = i;
            iPhaseEnd = i;

            model.addRow(new Object[] { p.start + 1 + (wsize - 1), p.end + 1, p.dist.toString(), p.bound });
        } else {
            // distribution is the same (also parameters), phase is extended
            iPhaseEnd++;
        }
    }

    p = new Phase(iPhaseBegin, iPhaseEnd + (wsize - 1));
    p.dist = lastDist;
    p.bound = trace.getSubTrace(p.start, p.end).getBound(coverage);

    model.addRow(new Object[] { p.start + 1 + (wsize - 1), p.end + 1, p.dist.toString(), p.bound });
    tablePhases.setModel(model);
}