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:gdt.jgui.tool.JEntityEditor.java

private void addRow() {
    try {//from www .j  a v a2s  .c  om
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.addRow(new String[] { null, "Name" + String.valueOf(model.getRowCount()), "Value" });
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:ExtendedDnDDemo.java

protected void importString(JComponent c, String str) {
    JTable target = (JTable) c;
    DefaultTableModel model = (DefaultTableModel) target.getModel();
    int index = target.getSelectedRow();

    //Prevent the user from dropping data back on itself.
    //For example, if the user is moving rows #4,#5,#6 and #7 and
    //attempts to insert the rows after row #5, this would
    //be problematic when removing the original rows.
    //So this is not allowed.
    if (rows != null && index >= rows[0] - 1 && index <= rows[rows.length - 1]) {
        rows = null;/*  w ww .j a  v  a 2 s.com*/
        return;
    }

    int max = model.getRowCount();
    if (index < 0) {
        index = max;
    } else {
        index++;
        if (index > max) {
            index = max;
        }
    }
    addIndex = index;
    String[] values = str.split("\n");
    addCount = values.length;
    int colCount = target.getColumnCount();
    for (int i = 0; i < values.length && i < colCount; i++) {
        model.insertRow(index++, values[i].split(","));
    }
}

From source file:gdt.jgui.tool.JEntityEditor.java

private Core[] getContent(boolean selected) {
    try {/*from w w w. jav a  2 s.  c om*/
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int cnt = model.getRowCount();
        if (cnt < 1)
            return null;
        ArrayList<Core> cl = new ArrayList<Core>();
        for (int i = 0; i < cnt; i++) {
            if (selected)
                if (!listModel.isSelectedIndex(i))
                    continue;
            cl.add(new Core((String) model.getValueAt(i, 0), (String) model.getValueAt(i, 1),
                    (String) model.getValueAt(i, 2)));
        }
        return cl.toArray(new Core[0]);
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
    return null;
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private void replaceTable(Core[] ca) {
    try {//  w  w w . j  a  va 2  s  .c  o  m
        table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        while (model.getRowCount() > 0)
            model.removeRow(0);
        int cnt = ca.length;
        if (cnt < 1)
            return;
        for (int i = 0; i < cnt; i++)
            model.addRow(new String[] { ca[i].name, ca[i].value });
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private void addRow() {
    try {//from  w  w  w . jav a2 s  . c om
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.addRow(new String[] { "Name" + String.valueOf(model.getRowCount()), "Value" });
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java

protected JPanel getPanel(final JDialog dialog, DefaultTableModel tModel, ArrayList<String> rowIdentifiers) {
    JPanel panel = new JPanel();
    JButton close = new JButton("Close");
    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);// w  w w .  ja v a2s  . c o  m
        }
    });
    close.setAlignmentX(Component.CENTER_ALIGNMENT);

    RowHeaderTable table = new RowHeaderTable(tModel);
    table.getDataTable().setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.getDataTable().setDefaultRenderer(Object.class, new ColorRenderer(false));
    table.setCellsEditable(false);
    table.setHeadersEditable(false);

    for (int r = 0; r < tModel.getRowCount() && rowIdentifiers.size() <= tModel.getRowCount(); r++) {
        table.getRowHeaderModel().setValueAt(rowIdentifiers.get(r), r, 0);
    }

    Dimension d = table.getRowHeaderTable().getPreferredScrollableViewportSize();
    d.width = 55;
    table.getRowHeaderTable().setPreferredScrollableViewportSize(d);

    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.add(table);
    panel.add(Box.createRigidArea(new Dimension(0, 5)));
    panel.add(close);

    return panel;
}

From source file:frames.MainGUI.java

public void writeReport() {
    for (int i = 0; i < REPORT_FILES.length; i++) {
        try {//from w w  w .ja  v  a2  s. co m
            //                FileWriter fw = new FileWriter(REPORT_FILES[i]);
            //                File f = new File(REPORT_FILES[i]);
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(REPORT_FILES[i]), "UTF-8"));
            //                BufferedWriter writer = new BufferedWriter(fw);
            DefaultTableModel model = (DefaultTableModel) REPORT_TABLES[i].getModel();
            String s = "";
            for (int k = 0; k < model.getColumnCount(); k++) {
                s += model.getColumnName(k) + ",";
            }
            s += "\n";
            int rows = model.getRowCount();

            for (int j = 0; j < rows; j++) {
                s += this.getTableRow(REPORT_TABLES[i], j);
            }
            writer.write(s);
            writer.close();

        } catch (Exception ex) {
        }

    }
}

From source file:com.smanempat.controller.ControllerEvaluation.java

private double[][] evaluationModel(JTable tableResult, JTable tableConfMatrix, JLabel totalAccuracy,
        JTable tableTahunTesting, JTable tableDataSetTesting, String[] knnValue, int nilaiK, JPanel panelChart)
        throws SQLException {
    int actIPA = 0;
    int actIPS = 0;
    int trueIPA = 0;
    int falseIPA = 0;
    int trueIPS = 0;
    int falseIPS = 0;
    int classIPA = 0;
    int classIPS = 0;

    double recIPA;
    double recIPS;
    double preIPA;
    double preIPS;
    double accuracy;

    DefaultTableModel tableModelConf = (DefaultTableModel) tableConfMatrix.getModel();
    DefaultTableModel tableModelRes = (DefaultTableModel) tableResult.getModel();
    String[] tempJurusan = getJurusanTest(tableTahunTesting, tableDataSetTesting);

    if (tableModelRes.getRowCount() != 0) {
        tableModelRes.setRowCount(0);/*from  w w w  .  j  ava  2 s  . com*/
    }

    for (int j = 0; j < tableDataSetTesting.getRowCount(); j++) {
        String nis = tableDataSetTesting.getValueAt(j, 0).toString();
        String jurusan = tempJurusan[j];
        String classified = knnValue[j];
        Object[] tableContent = { nis, jurusan, classified };
        tableModelRes.addRow(tableContent);
        tableResult.setModel(tableModelRes);
    }

    /*Hitung Jumlah Data Actual IPA dan IPS*/
    for (int j = 0; j < tempJurusan.length; j++) {
        if (tempJurusan[j].equals("IPA")) {
            actIPA = actIPA + 1;
        } else if (tempJurusan[j].equals("IPS")) {
            actIPS = actIPS + 1;
        }
    }

    /*Hitung Jumlah Data Classified IPA dan IPS*/
    for (int j = 0; j < knnValue.length; j++) {
        if (tableResult.getValueAt(j, 1).equals("IPA")) {
            if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) {
                trueIPA = trueIPA + 1;
            } else {
                falseIPS = falseIPS + 1;
            }
        } else if (tableResult.getValueAt(j, 1).equals("IPS")) {
            if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) {
                trueIPS = trueIPS + 1;
            } else {
                falseIPA = falseIPA + 1;
            }
        }
    }
    //        System.out.println("trueIPA =" + trueIPA);
    //        System.out.println("falseIPA =" + falseIPA);
    //        System.out.println("falseIPS =" + falseIPS);
    //        System.out.println("trueIPS =" + trueIPS);

    /*Hitung Nilai Recall, Precision, dan Accuracy*/
    preIPA = (double) trueIPA / (trueIPA + falseIPA);
    preIPS = (double) trueIPS / (trueIPS + falseIPS);
    recIPA = (double) trueIPA / (trueIPA + falseIPS);
    recIPS = (double) trueIPS / (trueIPS + falseIPA);
    accuracy = (double) (trueIPA + trueIPS) / (trueIPA + trueIPS + falseIPA + falseIPS);

    /*Tampung Nilai Recall, Precision, dan Accuracy*/
    double[][] tempEval = new double[3][1];
    tempEval[0][0] = accuracy;
    tempEval[1][0] = recIPA;
    tempEval[2][0] = preIPA;

    /*Set Nilai TF, TN, FP, FN ke Tabel Confusion Matrix*/
    tableModelConf.setValueAt("Actual IPA", 0, 0);
    tableModelConf.setValueAt("Actual IPS", 1, 0);
    tableModelConf.setValueAt("Class Precision", 2, 0);
    tableModelConf.setValueAt(trueIPA, 0, 1);
    tableModelConf.setValueAt(falseIPS, 0, 2);
    tableModelConf.setValueAt(falseIPA, 1, 1);
    tableModelConf.setValueAt(trueIPS, 1, 2);

    /*Set Nilai Recall, Precision, dan Accuracy ke Tabel Confusion Matrix*/
    if (Double.isNaN(preIPA)) {
        tableModelConf.setValueAt("NaN" + " %", 2, 1);
    } else {
        tableModelConf.setValueAt(df.format(preIPA * 100) + " %", 2, 1);
    }
    if (Double.isNaN(preIPS)) {
        tableModelConf.setValueAt("NaN" + " %", 2, 2);
    } else {
        tableModelConf.setValueAt(df.format(preIPS * 100) + " %", 2, 2);
    }
    if (Double.isNaN(recIPA)) {
        tableModelConf.setValueAt("NaN" + " %", 0, 3);
    } else {
        tableModelConf.setValueAt(df.format(recIPA * 100) + " %", 0, 3);
    }
    if (Double.isNaN(recIPS)) {
        tableModelConf.setValueAt("NaN" + " %", 1, 3);
    } else {
        tableModelConf.setValueAt(df.format(recIPS * 100) + " %", 1, 3);
    }
    if (Double.isNaN(accuracy)) {
        totalAccuracy.setText("Overall Accuracy is " + "NaN" + " %");
    } else {
        totalAccuracy.setText("Overall Accuracy is " + df.format(accuracy * 100) + " %");
    }
    //        System.out.println("Recall IPA = " + recIPA);
    //        System.out.println("Recall IPA =" + recIPS);
    //        System.out.println("Precision IPA  = " + preIPA);
    //        System.out.println("Precision IPS  = " + preIPS);
    //        System.out.println("Overall Accuracy  = " + accuracy);
    return tempEval;
}

From source file:UserInterface.Supplier.SalesOverviewJPanel.java

public void populateTable() {
    DefaultTableModel dtm = (DefaultTableModel) performanceJTable.getModel();
    dtm.setRowCount(0);//w w  w. j av  a2s . c  o  m
    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:main.java.edu.isistan.genCom.gui.Principal.java

/**
  * Elimina las filas de una tabla/*from w  ww  . j  a  v a 2 s.  com*/
  * 
  * @param dtm
  *            Modelo de la tabla
  */
 private void limpiarModelo(DefaultTableModel dtm) {
     int j = dtm.getRowCount();
     for (int i = j - 1; i >= 0; i--) {
         dtm.removeRow(i);
     }
 }