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:Software_Jframes.chart.java

void print_pdf_report(JTable jTable5) {
    Access ac = new Access();
    try {/*from  ww w  .  j  av  a 2 s  . c  o  m*/
        String filename = ac.chooseFile();

        com.itextpdf.text.Document document = new com.itextpdf.text.Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));

        document.open();
        document.add(new Paragraph(""));

        Image image1 = Image.getInstance("src/images/ROPA_Logo_without_claim.jpg");
        document.add(new Paragraph(""));
        image1.scaleAbsolute(80, 50);
        image1.setAbsolutePosition(50, 800);

        document.add(image1);
        PdfPTable table = new PdfPTable(3); // 3 columns.

        DefaultTableModel dtm = (DefaultTableModel) jTable5.getModel();
        Vector v = new Vector();
        int count_row = dtm.getRowCount();
        int count_col = dtm.getColumnCount();

        for (int i = 0; i < count_row; i++) {
            for (int j = 0; j < count_col; j++) {

                table.addCell(new PdfPCell(new Paragraph(dtm.getValueAt(i, j) + "")));

            }
        }
        table.setWidthPercentage(100);
        float[] columnWidths = { 2f, 1f, 1f };

        table.setWidths(columnWidths);

        document.add(table);
        document.close();
        JOptionPane.showMessageDialog(null, "Successfully Created.");

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

From source file:com.emr.mappings.MappingsForm.java

/**
 * Method to get the contents of a {@link JTable} as an array
 * @param table {@link JTable} The table to be parsed
 * @return {@link Object[][]} A multidimensional array 
 *///  w  ww  .  ja va  2  s .c o m
public Object[][] getTableData(JTable table) {
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
    Object[][] tableData = new Object[nRow][nCol];
    for (int i = 0; i < nRow; i++)
        for (int j = 0; j < nCol; j++) {

            if (dtm.getValueAt(i, j) != null) {
                tableData[i][j] = dtm.getValueAt(i, j);
            }
        }
    return tableData;
}

From source file:gui.ResultadoDistFreq.java

public void preencherTabela(ArrayList<String> valores, int[] freqAbs) {
    DefaultTableModel modelo = (DefaultTableModel) tabelaItens.getModel();
    int totalValores = 0;

    for (int i = 0; i < freqAbs.length; i++) {
        totalValores += freqAbs[i];//w w  w . j  a  v a 2s.co  m
    }

    modelo.setRowCount(valores.size());
    for (int i = 0; i < modelo.getRowCount(); i++) {
        modelo.setValueAt(("" + (i + 1)), i, 0);
        modelo.setValueAt(valores.get(i), i, 1);
        modelo.setValueAt(String.valueOf(freqAbs[i]), i, 2);
        modelo.setValueAt(String.valueOf((((freqAbs[i] * 1.0) / 25) * 100)), i, 3);
    }
}

From source file:gtu._work.ui.JSFMakerUI_attrDialog.java

public String getAttribute() {
    DefaultTableModel model = (DefaultTableModel) attrTable.getModel();
    Attribute attr = null;/*w  w  w  .  java 2 s . com*/
    boolean enable = false;
    StringBuilder sb = new StringBuilder();
    for (int ii = 0; ii < model.getRowCount(); ii++) {
        attr = (Attribute) model.getValueAt(ii, Function.VALUE.col);
        enable = (Boolean) model.getValueAt(ii, Function.ENABLE.col);
        if (StringUtils.isNotEmpty(attr.value) && enable) {
            sb.append(String.format(" %s=\"%s\"", attr.name, attr.value));
        }
    }
    return sb.toString();
}

From source file:UserInterface.AdminWorkArea.InventoryUsageJPanel.java

private void usageJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usageJButtonActionPerformed
    DefaultTableModel dtm = (DefaultTableModel) deviceUsageJTable.getModel();
    int rows = dtm.getRowCount();

    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (int i = 0; i < rows; i++) {
        int num = (int) deviceUsageJTable.getValueAt(i, 1);
        dataSet.setValue(num, "Number Of Reservations", String.valueOf(deviceUsageJTable.getValueAt(i, 0)));
    }//from   www .j a v a2s.  c  o  m

    JFreeChart chart = ChartFactory.createBarChart("Device Usage Chart", "Device Name",
            "Number of Reservations", dataSet, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.BLACK);

    ChartFrame frame = new ChartFrame("Sales Overview", chart);
    frame.setVisible(true);
    frame.setSize(600, 600);
}

From source file:de.stefanwndelmann.zy1270logger.ZY1270LoggerMain.java

/**
 * Reads the Data from the JTable and returns it as a CSV String.
 * //from w  w  w .j a v a 2 s  . co  m
 * @return 
 */
private String getCSVData() {
    DefaultTableModel dtm = (DefaultTableModel) resultTable.getModel();
    int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
    String data = "";
    for (int i = 0; i < nCol; i++) {
        data += dtm.getColumnName(i) + ";";
    }
    data = data.substring(0, data.length() - 1) + "\n";
    for (int i = 0; i < nRow; i++) {
        for (int j = 0; j < nCol; j++) {
            data += dtm.getValueAt(i, j) + ";";
        }
        data = data.substring(0, data.length() - 1) + "\n";
    }
    return data;
}

From source file:UserInterface.AdminWorkArea.InventoryUsageJPanel.java

public void findTopDevice() {

    int max = 0;/*from ww w  . j  a va2 s  . co  m*/
    int current = 0;
    String currentPName = "null";
    ArrayList<String> currentPList = new ArrayList<>();
    currentPList.add("null");
    DefaultTableModel dtm = (DefaultTableModel) deviceUsageJTable.getModel();

    for (int i = 0; i < dtm.getRowCount(); i++) {
        current = (int) dtm.getValueAt(i, 1);
        if (max < current) {
            max = current;
            IDeviceType dt = (IDeviceType) dtm.getValueAt(i, 0);
            currentPName = dt.getTypeOfDevice();
            currentPList.clear();
            currentPList.add(currentPName);
        } else if (max == current) {
            IDeviceType dt = (IDeviceType) dtm.getValueAt(i, 0);
            currentPName = dt.getTypeOfDevice();
            currentPList.add(currentPName);
        }
    }
    mostUsedLabel.setText(currentPList.toString());
}

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

private DefaultTableModel sort(DefaultTableModel dtm) {
    DefaultTableModel tmp = dtm;
    for (int i = 0; i < tmp.getRowCount(); i++) {
        int[] permutation = getRanksDescending(tmp, i);
        //System.out.println("Cost of permutation: " + getPermutationCost(permutation) + " on column " + i);
        //System.out.println("Permutation: "+Arrays.toString(permutation));
        tmp = sortByRows(tmp, permutation);
        tmp = sortByColumns(tmp, permutation);
    }/*  w w w.java 2  s .c om*/
    return tmp;
}

From source file:view.transacao.Relatorio.java

public void limpaTabela() {
    DefaultTableModel dm = (DefaultTableModel) jTable1.getModel();
    int rowCount = dm.getRowCount();

    for (int i = rowCount - 1; i >= 0; i--) {
        dm.removeRow(i);/*from  ww w.j a  v a  2s  . c o  m*/
    }
}

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

private int[] getRanksDescending(DefaultTableModel dtm, int column) {
    int rows = dtm.getRowCount();

    int[] ranks = new int[rows];
    List<Tuple2D<Double, Integer>> valueToIndex = new ArrayList<>();
    for (int i = 0; i < rows; i++) {
        Object o = dtm.getValueAt(i, column);
        if (o instanceof Double) {
            Double d = (Double) o;
            valueToIndex.add(new Tuple2D<>(d, i));
        } else if (o instanceof String) {
            Double d = Double.parseDouble((String) o);
            valueToIndex.add(new Tuple2D<>(d, i));
        }/*from  www.  j  ava 2s .c o  m*/
    }

    Collections.sort(valueToIndex, new Comparator<Tuple2D<Double, Integer>>() {

        @Override
        public int compare(Tuple2D<Double, Integer> t, Tuple2D<Double, Integer> t1) {
            return t.getFirst().compareTo(t1.getFirst());
        }
    });

    for (int i = 0; i < ranks.length; i++) {
        ranks[i] = valueToIndex.get(i).getSecond();
    }

    return ranks;
}