Example usage for javax.swing.table DefaultTableModel getRowCount

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

Introduction

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

Prototype

public int getRowCount() 

Source Link

Document

Returns the number of rows in this data table.

Usage

From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java

private DefaultTableModel removeColumn(DefaultTableModel dtm, int column) {
    Object[][] data = new Object[dtm.getRowCount()][dtm.getColumnCount() - 1];
    Object[] names = new Object[dtm.getColumnCount() - 1];
    int cnt = 0;/*from www . j  a  v  a 2s .  com*/
    for (int j = 0; j < dtm.getColumnCount(); j++) {
        if (j != column) {
            names[cnt++] = dtm.getColumnName(j);
        }
    }
    for (int i = 0; i < dtm.getRowCount(); i++) {
        cnt = 0;
        for (int j = 0; j < dtm.getColumnCount(); j++) {
            if (j != column) {
                data[i][cnt++] = dtm.getValueAt(i, j);
            }
        }
    }
    Logger.getLogger(getClass().getName()).log(Level.INFO,
            "Table model has {0} rows and {1} columns with {2} labels",
            new Object[] { data.length, data[0].length, names.length });
    return new DefaultTableModel(data, names);
}

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

private void clearButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_clearButtonActionPerformed
{//GEN-HEADEREND:event_clearButtonActionPerformed
    DefaultTableModel model = (DefaultTableModel) videoTable.getModel();
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i);//from  ww w  . ja  va  2s .c  o  m
    }
}

From source file:UserInterface.AdminWorkArea.InventoryUsageJPanel.java

public void findLeastUsedDevices() {
    int min = 0;// w  w  w.j a v a  2 s  . c  om
    int current = 0;
    String currentPName = "null";
    ArrayList<String> currentPList = new ArrayList<>();
    currentPList.add("null");
    DefaultTableModel dtm = (DefaultTableModel) deviceUsageJTable.getModel();
    min = (int) dtm.getValueAt(0, 1);
    for (int i = 0; i < dtm.getRowCount(); i++) {
        current = (int) dtm.getValueAt(i, 1);
        if (min > current) {
            min = current;
            IDeviceType dt = (IDeviceType) dtm.getValueAt(i, 0);
            currentPName = dt.getTypeOfDevice();
            currentPList.clear();
            currentPList.add(currentPName);
        } else if (min == current) {
            IDeviceType dt = (IDeviceType) dtm.getValueAt(i, 0);
            currentPName = dt.getTypeOfDevice();
            currentPList.add(currentPName);
        }
    }
    leastUsedLabel.setText(currentPList.toString());
}

From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java

private DefaultTableModel sortByRows(DefaultTableModel dtm, int[] permutation) {
    Object[][] modelByRows = new Object[dtm.getRowCount()][dtm.getColumnCount()];
    for (int i = 0; i < dtm.getRowCount(); i++) {
        modelByRows[i] = new Object[dtm.getColumnCount()];
        for (int j = 0; j < dtm.getColumnCount(); j++) {
            Object o = dtm.getValueAt(permutation[i], j);
            //if(o instanceof Double) {
            modelByRows[i][j] = o;//from w  w  w  .j a  v a  2  s  .  c  o m
            //}
        }
    }
    Object[] names = new Object[dtm.getRowCount()];
    for (int i = 0; i < dtm.getRowCount(); i++) {
        names[i] = dtm.getColumnName(permutation[i]);
    }
    Logger.getLogger(getClass().getName()).log(Level.INFO,
            "Table model has {0} rows and {1} columns with {2} labels",
            new Object[] { modelByRows.length, modelByRows[0].length, names.length });
    return new DefaultTableModel(modelByRows, names);
}

From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java

private DefaultTableModel sortByColumns(DefaultTableModel dtm, int[] permutation) {
    Object[][] modelByRows = new Object[dtm.getRowCount()][dtm.getColumnCount()];
    for (int i = 0; i < dtm.getRowCount(); i++) {
        modelByRows[i] = new Object[dtm.getColumnCount()];
        for (int j = 0; j < dtm.getColumnCount(); j++) {
            Object o = dtm.getValueAt(i, permutation[j]);
            //if(o instanceof Double) {
            modelByRows[i][j] = o;/*ww w  .  ja  va 2  s  . c  o  m*/
            //}
        }
    }
    Object[] names = new Object[dtm.getRowCount()];
    for (int i = 0; i < dtm.getRowCount(); i++) {
        names[i] = dtm.getColumnName(permutation[i]);
    }
    Logger.getLogger(getClass().getName()).log(Level.INFO,
            "Table model has {0} rows and {1} columns with {2} labels",
            new Object[] { modelByRows.length, modelByRows[0].length, names.length });
    return new DefaultTableModel(modelByRows, names);
}

From source file:userInterface.SystemAdmin.PovertyAnalysisJPanel.java

private void downloadPDFJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadPDFJButtonActionPerformed
    Document document = new Document();
    try {/*from ww w. ja v a  2s. co  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf"));
        document.open();

        Font helveticaBold = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.NORMAL, new GrayColor(1));
        Font helveticaNormal = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new GrayColor(1));

        Paragraph paragraphOne = new Paragraph("Safety Meter Report", helveticaBold);
        document.add(paragraphOne);
        document.add(new Paragraph("  "));
        DefaultTableModel model = (DefaultTableModel) povertyJTable.getModel();
        int numRows = model.getRowCount();
        int numColum = model.getColumnCount();
        int i, j = 0;
        for (i = 0; i < numRows; i++) {
            Paragraph info = new Paragraph("Network Name is " + model.getValueAt(i, 0), helveticaNormal);
            Paragraph sectionContent3 = new Paragraph(
                    "Average Income of A Person is $" + model.getValueAt(i, 2), helveticaNormal);
            info.add(sectionContent3);
            Paragraph sectionContent1 = new Paragraph("Crime Rate is " + model.getValueAt(i, 6) + "%",
                    helveticaNormal);
            info.add(sectionContent1);
            Paragraph sectionContent2 = new Paragraph("Poverty Rate is " + model.getValueAt(i, 4) + "%",
                    helveticaNormal);
            info.add(sectionContent2);
            Paragraph sectionContent4 = new Paragraph(
                    "Percentage of People Having FireArms " + model.getValueAt(i, 3) + "%", helveticaNormal);
            info.add(sectionContent4);
            document.add(info);
            Paragraph space = new Paragraph("   ", helveticaNormal);
            document.add(space);
        }
        //document.add(table);
        document.close();
        writer.close();
        JOptionPane.showMessageDialog(povertyJTable, "Please visit Downloads folder to view your report");

    } catch (Exception e) {
        JOptionPane.showMessageDialog(povertyJTable, e);
    }
}

From source file:HW3.java

public static void deleteAllRows(final DefaultTableModel model) {
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i);/*ww w. j a v a2 s .  c om*/
    }
}

From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java

private void inboundNewButtonActionPerformed(ActionEvent evt) {
    DefaultTableModel model = ((DefaultTableModel) inboundReplacementTable.getModel());
    int row = model.getRowCount();

    model.addRow(new Object[] { "", "" });

    inboundReplacementTable.setRowSelectionInterval(row, row);

    parent.setSaveEnabled(true);//from   ww w.  j  a  v a2 s.c  om
}

From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java

private void outboundNewButtonActionPerformed(ActionEvent evt) {
    DefaultTableModel model = ((DefaultTableModel) outboundReplacementTable.getModel());
    int row = model.getRowCount();

    model.addRow(new Object[] { "", "" });

    outboundReplacementTable.setRowSelectionInterval(row, row);

    parent.setSaveEnabled(true);/*from   w  w  w .j a va 2s.c o  m*/
}

From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java

private int[] getMinCostPermutation(DefaultTableModel dtm, int from) {
    int minPermCost = Integer.MAX_VALUE;
    int[] minPerm = null;
    for (int i = 0; i < dtm.getRowCount(); i++) {
        int[] permutation = getRanksDescending(dtm, i);
        int pc = getPermutationCost(permutation);

        //System.out.println("Permutation: "+Arrays.toString(permutation));
        //exclude trivial case of identity permutation
        if (pc < minPermCost && pc > 0 && i >= from) {
            //System.out.println("Cost of permutation: "+pc+ " on column "+i);
            minPermCost = pc;//from  w ww .j  a  v  a2  s .  c o  m
            minPerm = permutation;
        }
    }
    return minPerm;
}