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:com.farouk.projectapp.FirstGUI.java

private void UpdatejTable2() {
    DefaultTableModel modelPortfolio = new DefaultTableModel();
    total = new BigDecimal(0);
    modelPortfolio.setColumnIdentifiers(new String[] { "Name", "Symbol", "Stock Price ()", "Bid Price",
            "Ask Price", "Quantity Bought", "Price Paid" });
    for (Company com : SQLConnect.getPortfolioCompanies(userID)) {
        modelPortfolio
                .addRow(new String[] { com.getName(), com.getSymbol(),
                        String.valueOf(com.getStockPrice().doubleValue()),
                        String.valueOf(com.getBidPrice().doubleValue()),
                        String.valueOf(com.getAskPrice().doubleValue()), Integer.toString(com.getNumberOwned()),
                        String.valueOf((com.getStockPrice()
                                .multiply(new BigDecimal(Integer.toString(com.getNumberOwned())))
                                .doubleValue())) });
        String disturbed = Integer.toString(com.getNumberOwned());
        BigDecimal aa = new BigDecimal(disturbed);
        total = total.add(com.getStockPrice().multiply(aa));
    }/* w  w  w. j  a v a 2 s.  c  om*/
    jLabel10.setText("Total is : " + String.valueOf(total.doubleValue()) + "");
    jTable2.setModel(modelPortfolio);

}

From source file:userinterface.DoctorWorkArea.DiagnosePatientJPanel.java

public void populateVitalSignTable() {

    DefaultTableModel dtm = (DefaultTableModel) vitalSignTable.getModel();

    int rowcount = vitalSignTable.getRowCount();

    for (int i = rowcount - 1; i >= 0; i--) {
        dtm.removeRow(i);//from  ww w  .j  a  v  a2s  .c  o m
    }
    Employee patient = (Employee) patientCombo.getSelectedItem();

    for (VitalSign vs : patient.getMedicalRecord().getVitalSignHistory().getVitalSignList()) {
        Object row[] = new Object[2];
        row[0] = vs;
        row[1] = vs.getStatusReport();
        dtm.addRow(row);
    }

}

From source file:HW3.java

private void displayReviewTable(ResultSet result) throws SQLException {
    TableColumnModel tableModel = jTable1.getColumnModel();
    tableModel.getColumn(2).setPreferredWidth(300);
    tableModel.getColumn(3).setPreferredWidth(200);
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

    while (result.next()) {
        String date = result.getDate(7) + "";
        String stars = result.getInt(5) + "";
        String text = result.getString(6);
        String user = result.getString(4);
        String useful = result.getInt(2) + "";
        String cool = result.getInt(3) + "";
        String funny = result.getInt(1) + "";
        model.addRow(new Object[] { date, stars, text, user, useful, cool, funny });
        //System.out.println(date + " "+ stars + " "+ text + " "+ user + " "+ useful + " " + cool + " "+ funny);
    }/*  w w w  . j a v  a 2  s  .  c o  m*/
    topPanel.setVisible(false);
    //reviewPanel.repaint();
    jScrollPane3.setVisible(true);
    jTable1.setVisible(true);
    reviewPanel.setVisible(true);
    if (jTable1.getRowCount() == 0) {
        JOptionPane.showMessageDialog(reviewPanel, "NO Reviews tO DISPLAY", "Message",
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:org.agmip.ui.afsirs.frames.SWFrame.java

private void NLComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NLComboBoxActionPerformed
    // TODO add your handling code here:
    NL = NLComboBox.getSelectedIndex() + 1;
    DefaultTableModel model = (DefaultTableModel) soilTable.getModel();

    int row = model.getRowCount();
    for (int i = 0; i < row; i++) {
        model.removeRow(0);/* w w  w  . j  a  v  a 2  s  .c om*/
    }
    row = 0;
    if (row < NL) {
        while (row < NL) {
            Object[] vec = new Object[3];
            if (jRadioKeyboard.isSelected()) {
                vec[0] = row + 1;
                model.addRow(vec);
                row++;
                continue;
            }
            vec[0] = row + 1;
            vec[1] = Math.floor(DU[row] * 1000) / 1000;
            vec[2] = Math.floor(WC[row] * 1000) / 1000;

            model.addRow(vec);

            row++;
        }
    }
}

From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java

public void populateDoctorAlertTable() {
    DefaultTableModel dtm = (DefaultTableModel) alertRequestDetailsTable.getModel();
    dtm.setRowCount(0);//  w ww .j  a  v a2  s. com

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

                row[0] = request;
                UserAccount receiver = ((HospitalWorkRequest) request).getReceiver();
                row[1] = receiver == null ? "Doctor not assigned" : receiver;

                row[2] = request.getRequestDate();
                row[3] = request.getSeverity();
                row[4] = ((HospitalWorkRequest) request).getAlert();
                row[5] = request.getStatus();
                dtm.addRow(row);
            }
        }
    }
}

From source file:UserInterface.FinanceRole.TransferToRegSiteJPanel.java

private void populateLowRegSiteTable() {

    //Table//from   ww  w .j a v a2s . co  m
    DefaultTableModel dtm = (DefaultTableModel) lowRegJTable.getModel();
    dtm.setRowCount(0);

    for (CountryEnterprise objCountryEnterprise : objWorldEnterprise.getObjCountryEnterpriseDirectory()
            .getCountryEnterpriseList()) {
        for (RegisteredSiteEnterprise objRegisteredSiteEnterprise : objCountryEnterprise
                .getObjRegisteredSiteDirectory().getRegisteredSiteList()) {

            objRegisteredSiteEnterprise.getObjTransactionDirectory().updateTransactionAccount();

            BigDecimal availableBalance = objRegisteredSiteEnterprise.getObjTransactionDirectory()
                    .getAvailableRealBalance();
            int compare = availableBalance.compareTo(new BigDecimal(1000));

            if (compare < 1) {
                Object row[] = new Object[4];
                row[0] = objRegisteredSiteEnterprise.getOrganizationID();
                row[1] = objRegisteredSiteEnterprise.getRegSiteName();
                row[2] = objCountryEnterprise;
                row[3] = "$ "
                        + objRegisteredSiteEnterprise.getObjTransactionDirectory().getAvailableRealBalance();

                dtm.addRow(row);
            }
        }
    }
}

From source file:userinterface.CyberSecurity.CyberSecurityJPanel.java

private void populateEmployeeInfo() {
    DefaultTableModel model = (DefaultTableModel) employeeTable.getModel();
    employeeTable.removeAll();/*from w w w.jav  a  2 s .c o  m*/
    model.setRowCount(0);

    Organization organization = (Organization) organizationComboBox.getSelectedItem();
    UserAccountDirectory userAccountDirectory = organization.getUserAccountDirectory();

    if (null == userAccountDirectory) {
        return;
    }

    int serialNumber = 0;
    for (UserAccount userAccount : userAccountDirectory.getUserAccountList()) {
        LoginDetails latestLoginDetails = userAccount.getLatestLoginDetails();
        Employee employee = userAccount.getEmployee();
        List<Object> row = new ArrayList<>();
        row.add(++serialNumber);
        row.add(employee.getId());
        row.add(employee.getName());
        if (null != latestLoginDetails) {
            row.add(latestLoginDetails.getLoginDate() + " "
                    + LoginDetails.getFormattedTime(latestLoginDetails.getLoginTime()));
            row.add(latestLoginDetails.getLoginDate() + " "
                    + LoginDetails.getFormattedTime(latestLoginDetails.getLogoutTime()));
        } else {
            row.add("N/A");
            row.add("N/A");
        }
        model.addRow(row.toArray());
    }
}

From source file:userinterface.EnvironmentRole.PollutionCheckJPanel.java

public void populateTable() {
    int rowCount = tableCarOwners.getRowCount();
    DefaultTableModel model = (DefaultTableModel) tableCarOwners.getModel();
    for (int i = rowCount - 1; i >= 0; i--) {
        model.removeRow(i);// w ww . j  a v  a2s  .c om
    }
    for (WorkRequest request : environmentOrganization.getWorkQueue().getWorkRequestList()) {
        if (account == request.getReceiver() || request.getReceiver() == null) {
            Object[] row = new Object[5];
            row[0] = ((EnvironmentWorkRequest) request).getCarListing().getCarOwner().getName();
            row[1] = ((EnvironmentWorkRequest) request).getCarListing();

            String expectedPattern = "MM/dd/yyyy";
            SimpleDateFormat formatter = new SimpleDateFormat(expectedPattern);
            Date userInput = ((EnvironmentWorkRequest) request).getCarListing().getLastPollution(); // MM/DD/YYYY
            if (userInput != null) {
                String date = formatter.format(userInput);
                row[2] = date;
            } else {
                row[2] = null;
            }

            row[3] = ((EnvironmentWorkRequest) request);

            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            Calendar c = Calendar.getInstance();
            c.setTime(((EnvironmentWorkRequest) request).getCarListing().getLastPollution()); // Now use today date.
            c.add(Calendar.DATE, 90); // Adding 90 days
            String output = sdf.format(c.getTime());
            //                System.out.println(output);

            row[4] = output;

            model.addRow(row);
        }
    }

}

From source file:NewApplication.java

private void EditTable() {
    // TODO add your handling code here:

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

    model.setColumnCount(3);/*w w  w .  j av a  2  s  . c o m*/

    model.setNumRows(0);

    jTable2.setModel(model);

    TableColumn tc = jTable2.getColumnModel().getColumn(0);
    tc.setHeaderValue("Field Name");
    tc = jTable2.getColumnModel().getColumn(1);
    tc.setHeaderValue("Value");
    tc = jTable2.getColumnModel().getColumn(2);
    tc.setHeaderValue("Type");

    int index = listEntities.getSelectedIndex();

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

    try {

        Field[] fields = clazz.getDeclaredFields();

        for (Field f : fields) {

            Object[] obs = new Object[3];

            model = (DefaultTableModel) jTable2.getModel();

            f.setAccessible(true);

            obs[0] = f.getName();
            obs[2] = f.getType().getName();

            if (f.getName() == "" || f.getName() == null)
                continue;

            model.addRow(obs);

            jTable2.setModel(model);

        }

        jTable2.repaint();

    } catch (Exception ex) {
    }
    ;
}

From source file:userinterface.DoctorWorkArea.DiagnosePatientJPanel.java

public void populateLabRequestTable() {
    DefaultTableModel model = (DefaultTableModel) labTestRequestJTable.getModel();
    model.setRowCount(0);/* w w  w . ja va  2  s . co  m*/

    for (WorkRequest request : userAccount.getWorkQueue().getWorkRequestList()) {
        if (request instanceof LabTechnicianWorkRequest) {
            Object[] row = new Object[5];
            row[0] = request;
            row[1] = request.getMessage();
            row[2] = request.getReceiver();
            row[3] = request.getStatus();
            String result = ((LabTechnicianWorkRequest) request).getTestResult();
            row[4] = result == null ? "Waiting" : result;

            model.addRow(row);

        }
    }
}