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:userInterface.HospitalDoctor.HospitalDoctorWorkAreaJPanel.java

public void populatePatientsTable() {
    DefaultTableModel model = (DefaultTableModel) vitalSignjTable.getModel();
    model.setRowCount(0);/*from w  w w  .ja v  a  2 s.c om*/
    for (WorkRequest request : hdOrg.getWorkQueue().getWorkRequestList()) {
        if (request instanceof HospitalWorkRequest) {
            Person person = request.getPerson();
            for (Member mem : person.getMemberDir().getMemberDirectory()) {
                if (mem.getMemberName().equals(request.getMessage())) {
                    int patientAge = mem.getAge();
                    for (VitalSign vs : mem.getVitalSignList().getVitalSignList()) {
                        Object[] row = new Object[7];
                        row[0] = request;
                        row[1] = vs;
                        row[2] = vs.getRespiratoryRate();
                        row[3] = vs.getHeartRate();
                        row[4] = vs.getBloodPressure();
                        row[5] = vs.getTemperature();
                        row[6] = mem.getVitalSignList().VitalSignStatus(patientAge, vs);
                        model.addRow(row);
                    }
                }

            }

        }
    }
}

From source file:com.dvd.ui.SearchDVD.java

private void searchActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_searchActionPerformed
    errorTag.setVisible(false);/*from ww w .  j ava 2  s .com*/
    searchTable.setModel(new DefaultTableModel());
    String searchTerm = keyword.getText().toLowerCase();
    String ratingTerm = rating.getSelectedItem().toString();
    String yearTerm = year.getSelectedItem().toString();
    String definitionTerm = definition.getSelectedItem().toString();

    boolean isResultFound = false;

    DefaultTableModel model = new DefaultTableModel();
    model.setColumnIdentifiers(
            new String[] { "Code", "Title", "Year", "Rating ", "Definition", "Actors", "Book" });

    if (searchTerm != null && !searchTerm.isEmpty()) {

        for (Dvd dvd_item : searchDVDList) {
            if (dvd_item.getTitle().toLowerCase().contains(searchTerm)) {

                model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(),
                        String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()),
                        dvd_item.getDefiniiton(), dvd_item.getActors() });

            }
        }
        isResultFound = true;

        if (isResultFound) {
            searchTable.setVisible(true);
            searchTable.setModel(model);
        } else {
            errorTag.setVisible(true);
            searchTable.setModel(new DefaultTableModel());
            // errorTag.setText("No Result Found");
        }
    } else {

        if (!ratingTerm.equals("Any")) {
            for (Dvd dvd_item : searchDVDList) {
                if (dvd_item.getRating() == Integer.parseInt(ratingTerm)) {

                    model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(),
                            String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()),
                            dvd_item.getDefiniiton(), dvd_item.getActors() });

                }
            }
            isResultFound = true;

            if (isResultFound) {
                searchTable.setVisible(true);
                searchTable.setModel(model);
            } else {
                errorTag.setVisible(true);
                searchTable.setModel(new DefaultTableModel());
                errorTag.setText("No Result Found");
            }

        } else if (!yearTerm.equals("Any")) {

            for (Dvd dvd_item : searchDVDList) {
                if (dvd_item.getYear().equals(yearTerm)) {

                    model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(),
                            String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()),
                            dvd_item.getDefiniiton(), dvd_item.getActors() });

                }
            }
            isResultFound = true;

            if (isResultFound) {
                searchTable.setVisible(true);
                searchTable.setModel(model);
            } else {
                errorTag.setVisible(true);
                searchTable.setModel(new DefaultTableModel());
                errorTag.setText("No Result Found");
            }

        } else if (!definitionTerm.equals("Any")) {

            for (Dvd dvd_item : searchDVDList) {
                if (dvd_item.getDefiniiton().equals(definitionTerm)) {

                    model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(),
                            String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()),
                            dvd_item.getDefiniiton(), dvd_item.getActors() });

                }
            }
            isResultFound = true;

            if (isResultFound) {
                searchTable.setVisible(true);
                searchTable.setModel(model);
            } else {
                errorTag.setVisible(true);
                searchTable.setModel(new DefaultTableModel());
                errorTag.setText("No Result Found");
            }

        } else {
            errorTag.setText("Please enter more specific search criteria");
            errorTag.setVisible(true);
        }

        // errorTag.setText("No Result Found");
    }

}

From source file:frames.MainGUI.java

public void LoadFeeDataToJTable(JTable t, File file) {
    try {/*  ww w . j  av  a2  s.  c  o m*/
        CSVParser parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT);
        //t.setModel(tm);
        DefaultTableModel model = new DefaultTableModel();
        //model.setRowCount(0);
        for (CSVRecord c : parser) {
            if (c.getRecordNumber() == 1) {

                model.addColumn(c.get(datatype.GlobalVariable.TYPE));
                model.addColumn(c.get(datatype.GlobalVariable.AMOUNT));
                model.addColumn(c.get(datatype.GlobalVariable.PAID_BY));
                model.addColumn(c.get(datatype.GlobalVariable.PAYER));
                t.setModel(model);
                model = (DefaultTableModel) t.getModel();
                continue;
            }
            model.addRow(
                    new Object[] { c.get(datatype.GlobalVariable.TYPE), c.get(datatype.GlobalVariable.AMOUNT),
                            c.get(datatype.GlobalVariable.PAID_BY), c.get(datatype.GlobalVariable.PAYER) });
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:com.mirth.connect.connectors.file.AdvancedSftpSettingsDialog.java

private void initComponents() {
    authenticationLabel = new JLabel("Authentication:");

    usePasswordRadio = new JRadioButton("Password");
    usePasswordRadio.setFocusable(false);
    usePasswordRadio.setBackground(new Color(255, 255, 255));
    usePasswordRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    usePasswordRadio.setToolTipText("Select this option to use a password to gain access to the server.");
    usePasswordRadio.addActionListener(new ActionListener() {
        @Override/*from  w  w w  .  j a  v a2 s.  c om*/
        public void actionPerformed(ActionEvent e) {
            authenticationRadioButtonActionPerformed();
        }
    });

    usePrivateKeyRadio = new JRadioButton("Public Key");
    usePrivateKeyRadio.setSelected(true);
    usePrivateKeyRadio.setFocusable(false);
    usePrivateKeyRadio.setBackground(UIConstants.BACKGROUND_COLOR);
    usePrivateKeyRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    usePrivateKeyRadio
            .setToolTipText("Select this option to use a public/private keypair to gain access to the server.");
    usePrivateKeyRadio.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            authenticationRadioButtonActionPerformed();
        }
    });

    useBothRadio = new JRadioButton("Both");
    useBothRadio.setSelected(true);
    useBothRadio.setFocusable(false);
    useBothRadio.setBackground(UIConstants.BACKGROUND_COLOR);
    useBothRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    useBothRadio.setToolTipText(
            "Select this option to use both a password and a public/private keypair to gain access to the server.");
    useBothRadio.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            authenticationRadioButtonActionPerformed();
        }
    });

    privateKeyButtonGroup = new ButtonGroup();
    privateKeyButtonGroup.add(usePasswordRadio);
    privateKeyButtonGroup.add(usePrivateKeyRadio);
    privateKeyButtonGroup.add(useBothRadio);

    keyLocationLabel = new JLabel("Public/Private Key File:");
    keyLocationField = new JTextField();
    keyLocationField.setToolTipText(
            "The absolute file path of the public/private keypair used to gain access to the remote server.");

    passphraseLabel = new JLabel("Passphrase:");
    passphraseField = new JPasswordField();
    passphraseField.setToolTipText("The passphrase associated with the public/private keypair.");

    useKnownHostsLabel = new JLabel("Host Key Checking:");

    useKnownHostsYesRadio = new JRadioButton("Yes");
    useKnownHostsYesRadio.setFocusable(false);
    useKnownHostsYesRadio.setBackground(UIConstants.BACKGROUND_COLOR);
    useKnownHostsYesRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    useKnownHostsYesRadio.setToolTipText(
            "<html>Select this option to validate the server's host key within the provided<br>Known Hosts file. Known Hosts file is required.</html>");

    useKnownHostsAskRadio = new JRadioButton("Ask");
    useKnownHostsAskRadio.setFocusable(false);
    useKnownHostsAskRadio.setBackground(UIConstants.BACKGROUND_COLOR);
    useKnownHostsAskRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    useKnownHostsAskRadio.setToolTipText(
            "<html>Select this option to ask the user to add the server's host key to the provided<br>Known Hosts file. Known Hosts file is optional.</html>");

    useKnownHostsNoRadio = new JRadioButton("No");
    useKnownHostsNoRadio.setSelected(true);
    useKnownHostsNoRadio.setFocusable(false);
    useKnownHostsNoRadio.setBackground(UIConstants.BACKGROUND_COLOR);
    useKnownHostsNoRadio.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    useKnownHostsNoRadio.setToolTipText(
            "<html>Select this option to always add the server's host key to the provided<br>Known Hosts file. Known Hosts file is optional.</html>");

    knownHostsButtonGroup = new ButtonGroup();
    knownHostsButtonGroup.add(useKnownHostsYesRadio);
    knownHostsButtonGroup.add(useKnownHostsAskRadio);
    knownHostsButtonGroup.add(useKnownHostsNoRadio);

    knownHostsLocationLabel = new JLabel("Known Hosts File:");
    knownHostsField = new JTextField();
    knownHostsField
            .setToolTipText("The path to the local Known Hosts file used to authenticate the remote server.");

    configurationsLabel = new JLabel("Configuration Options:");
    configurationsTable = new MirthTable();

    Object[][] tableData = new Object[0][1];
    configurationsTable.setModel(new RefreshTableModel(tableData, new String[] { "Name", "Value" }));
    configurationsTable.setOpaque(true);
    configurationsTable.getColumnModel()
            .getColumn(configurationsTable.getColumnModel().getColumnIndex(NAME_COLUMN_NAME))
            .setCellEditor(new ConfigTableCellEditor(true));
    configurationsTable.getColumnModel()
            .getColumn(configurationsTable.getColumnModel().getColumnIndex(VALUE_COLUMN_NAME))
            .setCellEditor(new ConfigTableCellEditor(false));

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        configurationsTable.setHighlighters(highlighter);
    }

    configurationsScrollPane = new JScrollPane();
    configurationsScrollPane.getViewport().add(configurationsTable);

    newButton = new JButton("New");
    newButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultTableModel model = (DefaultTableModel) configurationsTable.getModel();

            Vector<String> row = new Vector<String>();
            String header = "Property";

            for (int i = 1; i <= configurationsTable.getRowCount() + 1; i++) {
                boolean exists = false;
                for (int index = 0; index < configurationsTable.getRowCount(); index++) {
                    if (((String) configurationsTable.getValueAt(index, 0)).equalsIgnoreCase(header + i)) {
                        exists = true;
                    }
                }

                if (!exists) {
                    row.add(header + i);
                    break;
                }
            }

            model.addRow(row);

            int rowSelectionNumber = configurationsTable.getRowCount() - 1;
            configurationsTable.setRowSelectionInterval(rowSelectionNumber, rowSelectionNumber);

            Boolean enabled = deleteButton.isEnabled();
            if (!enabled) {
                deleteButton.setEnabled(true);
            }
        }
    });

    deleteButton = new JButton("Delete");
    deleteButton.setEnabled(false);
    deleteButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int rowSelectionNumber = configurationsTable.getSelectedRow();
            if (rowSelectionNumber > -1) {
                DefaultTableModel model = (DefaultTableModel) configurationsTable.getModel();
                model.removeRow(rowSelectionNumber);

                rowSelectionNumber--;
                if (rowSelectionNumber > -1) {
                    configurationsTable.setRowSelectionInterval(rowSelectionNumber, rowSelectionNumber);
                }

                if (configurationsTable.getRowCount() == 0) {
                    deleteButton.setEnabled(false);
                }
            }
        }
    });

    okButton = new JButton("OK");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            okCancelButtonActionPerformed();
        }
    });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            dispose();
        }
    });

    authenticationRadioButtonActionPerformed();
}

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

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

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

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

    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);
    }/*  ww  w . j  a  v a  2 s.c om*/

    /*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;
            }
        }
    }

    /*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][tempK.length];
    tempEval[0][i] = accuracy;
    tempEval[1][i] = recIPA;
    tempEval[2][i] = preIPA;

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

    /*Set Nilai Recall, Precision, dan Accuracy ke Tabel Confusion Matrix*/
    if (Double.isNaN(preIPA)) {
        tableConfMatrix.setValueAt("NaN" + " %", 2, 1);
    } else {
        tableConfMatrix.setValueAt(df.format(preIPA * 100) + " %", 2, 1);
    }
    if (Double.isNaN(preIPS)) {
        tableConfMatrix.setValueAt("NaN" + " %", 2, 2);
    } else {
        tableConfMatrix.setValueAt(df.format(preIPS * 100) + " %", 2, 2);
    }
    if (Double.isNaN(recIPA)) {
        tableConfMatrix.setValueAt("NaN" + " %", 0, 3);
    } else {
        tableConfMatrix.setValueAt(df.format(recIPA * 100) + " %", 0, 3);
    }
    if (Double.isNaN(recIPS)) {
        tableConfMatrix.setValueAt("NaN" + " %", 1, 3);
    } else {
        tableConfMatrix.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) + " %");
    }

    tableModelRes.setRowCount(0);

    return tempEval;
}

From source file:userinterface.Citizen.CitizenWorkAreaJPanel.java

public void populateInhalerSensorData() {
    DefaultTableModel dtm = (DefaultTableModel) inhalerTable.getModel();
    dtm.setRowCount(0);//  w  ww. j  av a2  s  .co  m
    ArrayList<Date> keyList = new ArrayList<>(
            account.getCitizen().getHealthReport().getAsthamaInhalerSensor().getUsageHistory().keySet());
    Collections.sort(keyList);
    for (Date d : keyList) {
        Area area = account.getCitizen().getHealthReport().getAsthamaInhalerSensor().getUsageHistory().get(d);
        if (null != area) {
            Object row[] = new Object[2];
            row[0] = d.toString();
            row[1] = area;
            dtm.addRow(row);
        }
    }
}

From source file:uk.ac.ox.cbrg.cpfp.uploadapp.UploadApplet.java

private void addFiles(File[] files) {

    DefaultTableModel fileModel = (DefaultTableModel) fileTable.getModel();

    for (int i = 0; i < files.length; i++) {

        String filePath = files[i].getAbsolutePath();
        String fileName = files[i].getName();
        long fileSize = files[i].length();

        txtMessages.append("Selected file: " + fileName + "\n");

        UploadFile uf = new UploadFile(filePath, fileName, fileSize, "Not Uploaded");

        // Check if file already exists
        if (uploadFiles.contains(uf)) {
            JOptionPane.showMessageDialog(this, "File already in list:\n" + fileName);
        } else {//from  ww w  .  ja  v a 2  s  .  co  m
            // Add to upload queue list
            uploadFiles.add(uf);
            // Add to table
            fileModel.addRow(uf.getTableRow());
            // Allow upload once a file has been selected
            btnUpload.setEnabled(true);
        }

    }
}

From source file:main.java.edu.isistan.genCom.gui.Principal.java

private void cargarComision(int indice) {
     // // Carga la tabla de comisiones
     DefaultTableModel dtmComision = (DefaultTableModel) tbComision.getModel();
     limpiarModelo(dtmComision);//from www .j  a  v a2s  .  c  o  m

     List<Ejecucion> ejecuciones = generacionCargada.getEjecuciones();
     Ejecucion ejecucion = ejecuciones.get(indice);

     List<Investigador> comision = ejecucion.getComision();

     for (Investigador inv : comision) {
         dtmComision.addRow(new String[] { String.valueOf(comision.indexOf(inv)), inv.toString(),
                 String.valueOf(redSocial.getDegree(inv)), String.valueOf(redSocial.getBetweeness(inv)),
                 String.valueOf(redSocial.getCloseness(inv)), String.valueOf(redSocial.getEigenVector(inv)) });
     }
 }

From source file:Interface.FoodDistributionWorkArea.FoodDistributionWorkArea.java

public void populateHistoryTable() {

    DefaultTableModel model = (DefaultTableModel) tblFoodDistributionHistory.getModel();
    model.setRowCount(0);/*from  ww  w .j av  a  2  s  .c om*/
    for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) {
        if (request.getStatus().equalsIgnoreCase("Distributed")) {
            Object[] row = new Object[7];
            row[0] = ((FoodDistributionWorkRequest) request);
            row[1] = ((FoodDistributionWorkRequest) request).getFood().getFoodBarCode();
            row[2] = ((FoodDistributionWorkRequest) request).getFood().getQuantity();
            row[3] = ((FoodDistributionWorkRequest) request).getFood().getFoodExpiryDate();
            row[4] = ((FoodDistributionWorkRequest) request).getStatus();
            row[5] = ((FoodDistributionWorkRequest) request).getFood().getNumberOfBenificary();
            model.addRow(row);
        }

    }
}

From source file:frames.MainGUI.java

public void LoadRentToJtable(JTable t, File file) {
    try {//from  w  ww .j  a va  2  s .c  o  m
        CSVParser parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT);
        //t.setModel(tm);
        DefaultTableModel model = new DefaultTableModel();
        //model.setRowCount(0);
        for (CSVRecord c : parser) {
            if (c.getRecordNumber() == 1) {
                model.addColumn("??");
                model.addColumn("");
                model.addColumn("?");
                model.addColumn("?");
                model.addColumn("");
                model.addColumn("");
                t.setModel(model);
                model = (DefaultTableModel) t.getModel();
                continue;
            }
            model.addRow(new Object[] { c.get(0), c.get(1), c.get(2), c.get(3), c.get(4), c.get(5) });
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}