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:Interface.FoodDistributionWorkArea.FoodDistributionWorkArea.java

public void populateTable() {

    DefaultTableModel model = (DefaultTableModel) tblFoodDistribution.getModel();
    model.setRowCount(0);//from w  w w.j  a  v 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).getMessage();
            row[6] = ((FoodDistributionWorkRequest) request).getStandardSupervisor();
            model.addRow(row);
        }

    }
}

From source file:NewApplication.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

    model.setNumRows(0);/* w ww.ja va  2s  .  c  om*/

    jTable1.setModel(model);

    int index = listEntities.getSelectedIndex();

    if (index < 0)
        return;

    clazz = null;

    if (ens != null)
        clazz = (Class) ens.get(index);

    try {

        List<Object> acc = JavaApplication.GetEntities(clazz);

        int r = 0;

        int c = 0;

        for (Object a : acc) {

            Field[] fields = a.getClass().getDeclaredFields();

            Object[] obs = new Object[fields.length];

            model = (DefaultTableModel) jTable1.getModel();

            model.addRow(obs);

            jTable1.setModel(model);

            c = 0;

            for (Field field : fields) {

                field.setAccessible(true);

                Object v = field.get(a);

                if (v == null)
                    v = "";

                jTable1.getModel().setValueAt(v.toString(), r, c++);

            }

            r++;
        }

        jTable1.repaint();

        EditTable();

    } catch (Exception ex) {
    }
    ;
}

From source file:cish.CISH.java

/**
* Updates the CISH table in this plugin window.
*//*from   ww w  . j a v  a2 s .c  o m*/
void updateCISHTable() {

    DefaultTableModel tm = (DefaultTableModel) jXTable1.getModel();
    tm.setRowCount(0);
    for (int i = 0; i < tss.size(); i++) {
        int n_cep = 0;
        int n_gene = 0;
        for (int[] cp : ps[i]) {
            if (cp[2] == COLORS[0][0] && cp[3] == COLORS[0][1] && cp[4] == COLORS[0][2]) {
                n_cep++;
            } else if (cp[2] == COLORS[1][0] && cp[3] == COLORS[1][1] && cp[4] == COLORS[1][2]) {
                n_gene++;
            } else if (cp[2] == COLORS[4][0] && cp[3] == COLORS[4][1] && cp[4] == COLORS[4][2]) {
                n_cep++;
                n_gene++;
            }
        }
        tm.addRow(new Object[] { tss.get(i).getName(), n_cep, n_gene, gRatios[i], lRatios[i] });
    }
}

From source file:UserInterface.SystemAdmin.ReportsJPanel.java

private void populateCustomers(ArrayList<Customer> c) {

    DefaultTableModel model = (DefaultTableModel) customerTable.getModel();

    model.setRowCount(0);/*from w  w  w  .jav a  2 s  .  c o m*/
    if (c.size() != 0) {
        for (Customer cust : c) {
            Object[] row = new Object[5];

            row[0] = cust;
            row[1] = cust.getId();
            row[2] = cust.getContactNo();
            row[3] = cust.getEmailId();
            row[4] = Math.ceil(cust.getTotalUsageVolume()) + " Gallons";

            model.addRow(row);
        }
        noteCust.setText("");
    } else {
        model.setRowCount(0);
        noteCust.setText("*Note : No customers");
    }
}

From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java

public void populateTable(Person person) {
    DefaultTableModel model = (DefaultTableModel) applianceTable.getModel();
    TableColumnModel tcm = applianceTable.getColumnModel();
    CustomTableCellRenderer customCellRenderer = new CustomTableCellRenderer();
    model.setRowCount(0);/* w w  w.  ja v  a2s.  com*/
    if (person.getSensorsList().getSensorsList() != null) {
        for (Sensor sensor : person.getSensorsList().getSensorsList()) {
            Object[] row = new Object[5];
            row[0] = sensor;
            String appName = sensor.getSensorType().getValue();
            row[1] = appName;
            int watts = sensor.getNumberWatt();
            row[2] = watts;
            row[3] = sensor.getHours();
            row[4] = sensor.getConsumptionLevel();
            model.addRow(row);
            tcm.getColumn(4).setCellRenderer(customCellRenderer);
        }
        populateCalculations();
    }

}

From source file:org.jas.gui.MainWindow.java

@EventMethod(Events.LOAD_METADATA)
void onLoadMetadata(List<Metadata> metadatas) {
    JTable descriptionTable = getDescriptionTable();
    DefaultTableModel model = (DefaultTableModel) descriptionTable.getModel();
    for (Metadata metadata : metadatas) {
        int row = descriptionTable.getRowCount();
        model.addRow(new Object[] { "", "", "", "", "", "", "", "" });
        descriptionTable.setValueAt(metadata.getArtist(), row, ApplicationState.ARTIST_COLUMN);
        descriptionTable.setValueAt(metadata.getTitle(), row, ApplicationState.TITLE_COLUMN);
        descriptionTable.setValueAt(metadata.getAlbum(), row, ApplicationState.ALBUM_COLUMN);
        descriptionTable.setValueAt(metadata.getGenre(), row, ApplicationState.GENRE_COLUMN);
        descriptionTable.setValueAt(metadata.getYear(), row, ApplicationState.YEAR_COLUMN);
        descriptionTable.setValueAt(metadata.getTrackNumber(), row, ApplicationState.TRACK_NUMBER_COLUMN);
        descriptionTable.setValueAt(metadata.getTotalTracks(), row,
                ApplicationState.TOTAL_TRACKS_NUMBER_COLUMN);
        descriptionTable.setValueAt(metadata.getCdNumber(), row, ApplicationState.CD_NUMBER_COLUMN);
        descriptionTable.setValueAt(metadata.getTotalCds(), row, ApplicationState.TOTAL_CDS_NUMBER_COLUMN);
        if (metadata.isMetadataFromFile()) {
            descriptionTable.setValueAt(ApplicationState.NEW, row, ApplicationState.STATUS_COLUMN);
            metadataWithAlbum.add(metadata);
            getApplyButton().setEnabled(true);
        } else {/*from   ww w.  j a  v  a2s  .  com*/
            descriptionTable.setValueAt(ApplicationState.READY, row, ApplicationState.STATUS_COLUMN);
        }
    }
}

From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java

public void populateAlertTable() {
    DefaultTableModel dtm = (DefaultTableModel) alertDetailsTable.getModel();
    dtm.setRowCount(0);/*from   w  w  w  .j  a v  a2s  .c  o  m*/

    for (WorkRequest request : userAccount.getWorkQueue().getWorkRequestList()) {
        if (userAccount.getWorkQueue().getWorkRequestList() != null) {
            Object[] row = new Object[7];

            row[0] = request.getMessage();
            row[1] = request.getReceiver();
            row[2] = request.getSender();
            row[3] = ((HighEnergyConsumptionWorkRequest) request).getComment();
            row[4] = request.getStatus();
            row[5] = request.getRequestDate();
            row[6] = ((HighEnergyConsumptionWorkRequest) request).getResponse();
            // row[1] = request.getStatus();

            dtm.addRow(row);
        }
    }
}

From source file:UserInterface.PatientRole.ManageMyVitalSignsAndFitnessRecordJPanel.java

private void populateTable() {
    DefaultTableModel model = (DefaultTableModel) viewVitalSignsJTable1.getModel();
    model.setRowCount(0);//from www .j  a v a 2  s .  c o  m

    DoctorOrganization doctorOrganization = null;
    for (Organization o : enterprise.getOrganizationDirectory().getOrganizationList()) {
        if (o instanceof DoctorOrganization) {
            DoctorOrganization dO = (DoctorOrganization) o;
            doctorOrganization = dO;
            break;
        }
    }

    for (WorkRequest request : doctorOrganization.getWorkQueue().getWorkRequestList()) {
        if (request != null) {
            PatientDoctorWorkRequest patientDoctorWorkRequest = (PatientDoctorWorkRequest) request;
            Record r = patientDoctorWorkRequest.getRecord();
            Object[] row = new Object[5];
            row[0] = r;
            row[1] = r.getNormalOrNot();
            row[2] = r.getTotalTime();
            row[3] = r.getNeedMoreExcerciseOrNot();
            String respondStatus = patientDoctorWorkRequest.getRespondStatus();
            row[4] = respondStatus == null ? "Waiting" : respondStatus;

            model.addRow(row);

        }

    }
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void addMetaDataSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMetaDataSearchButtonActionPerformed
    DefaultTableModel model = ((DefaultTableModel) metaDataSearchTable.getModel());
    int row = model.getRowCount();

    List<MetaDataColumn> metaDataColumns = messageBrowser.getMetaDataColumns();
    if (metaDataColumns.size() > 0) {
        MetaDataColumn metaDataColumn = metaDataColumns.get(0);
        MetaDataSearchOperator operator = MetaDataSearchOperator.EQUAL;

        model.addRow(new Object[] { metaDataColumn.getName(), operator, "", false });

        metaDataSearchTable.setRowSelectionInterval(row, row);
    }/* w w  w.ja  v  a 2s  . c o m*/
}

From source file:dylemator.UserResultList.java

private void filenameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filenameComboActionPerformed
    Object item = this.filenameCombo.getSelectedItem();
    exportData = new ArrayList<String[]>();
    File file = new File(item.toString());
    if (file.exists()) {
        this.selectedFilename = item.toString();
        String datePattern = "(\\d+-\\d+-\\d+)";
        Pattern r = Pattern.compile(datePattern);
        Matcher m = r.matcher(file.getName());
        String fileDate;//from www  .  j av a  2 s. c om
        if (m.find()) {
            fileDate = m.group(0);
        } else
            fileDate = new Date(file.lastModified()).toString();

        DefaultTableModel codeModel = (DefaultTableModel) this.codeTable.getModel();
        DefaultTableModel infoModel = (DefaultTableModel) this.infoTable.getModel();
        DefaultTableModel resultsModel = (DefaultTableModel) this.resultsTable.getModel();
        codeModel.setRowCount(0);
        codeModel.setColumnCount(0);
        infoModel.setRowCount(0);
        infoModel.setColumnCount(2);
        resultsModel.setRowCount(0);
        resultsModel.setColumnCount(2);

        try {
            InputStreamReader input = new FileReader(file);
            BufferedReader bufferReader;
            bufferReader = new BufferedReader(input);
            // headers
            String headerLine = bufferReader.readLine();
            String[] headers = headerLine.split(";", -1);

            codeModel.addColumn(headers[0]);
            exportData.add((String[]) headers);

            String line;
            while ((line = bufferReader.readLine()) != null) {
                String[] fields = line.split(";", -1);
                exportData.add((String[]) fields);
                codeModel.addRow(new String[] { fields[0] });
            }

            bufferReader.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FindDialog.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(FindDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}