Example usage for javax.swing.table DefaultTableModel removeRow

List of usage examples for javax.swing.table DefaultTableModel removeRow

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel removeRow.

Prototype

public void removeRow(int row) 

Source Link

Document

Removes the row at row from the model.

Usage

From source file:fitmon.WorkoutLog.java

private void removeItem(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeItem

    if (evt.getClickCount() == 1) {
        JTable target = (JTable) evt.getSource();
        int row = target.getSelectedRow();
        int column = target.getSelectedColumn();
        String selectedwkt = (String) target.getValueAt(row, 0);
        //int index = selectedwkt.indexOf("--");
        // String foodName = selectedFood.substring(0, index);
        //int calorie = selectedFood.substring(index+2);
        if (target.getColumnName(target.getSelectedColumn()).equals("Edit")) {
            DefaultTableModel model = (DefaultTableModel) tab.getModel();
            model.removeRow(row);
            for (int i = 0; i < wkt.size(); i++) {
                if (wkt.get(i).getWorkout().equals(selectedwkt)) //&& wkt.get(i).getCal().equals(calorie))
                {/*from w ww  . j  a  v a  2 s .  c o  m*/
                    wkt.remove(i);
                    break;
                }
            }
        }
        // do some action if appropriate column
    }

    // TODO add your handling code here:
}

From source file:User.Interface.SupplierAdminRole.ReviewSalesJPanel.java

private void displayData() {
    try {// w w  w .  java2 s  . co  m

        //check if supplier has products
        if (supplierAdminOrganization.getMedicalDeviceCatalog().getMedicalDeviceList().size() < 1) {
            JOptionPane.showMessageDialog(this, "No products avaiailable from supplier");
            return;
        }

        int rowCount = productjTable.getRowCount();
        DefaultTableModel model = (DefaultTableModel) productjTable.getModel();
        for (int i = rowCount - 1; i >= 0; i--) {
            model.removeRow(i);
        }

        double totalSaleAmt = 0;
        int topSoldProductID = 1;

        for (MedicalDevice md : supplierAdminOrganization.getMedicalDeviceCatalog().getMedicalDeviceList()) {
            Object row[] = new Object[4];
            row[0] = md;
            row[1] = md.getDeviceId();
            row[2] = md.getSoldQuantity();
            double totalProductSale = (md.getPrice() * md.getSoldQuantity());
            row[3] = totalProductSale;
            model.addRow(row);

            totalSaleAmt = totalSaleAmt + totalProductSale;
            if (md.getSoldQuantity() > supplierAdminOrganization.getMedicalDeviceCatalog()
                    .getMedicalDeviceList().get(topSoldProductID - 1).getSoldQuantity()) {
                topSoldProductID = md.getDeviceId();
            }
        }

        if (totalSaleAmt > 0) {
            topSoldjTextField.setText(supplierAdminOrganization.getMedicalDeviceCatalog().getMedicalDeviceList()
                    .get(topSoldProductID - 1).getDeviceName());
            totalSalejTextField.setText(String.valueOf(totalSaleAmt));
        } else {
            topSoldjTextField.setText("None");
            totalSalejTextField.setText("0");
        }

    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "An error occurred");
    }
}

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);
    }/*from  www  . jav a2  s. com*/
    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:com.stanley.captioner.MainFrame.java

private void clearButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_clearButtonActionPerformed
{//GEN-HEADEREND:event_clearButtonActionPerformed
    DefaultTableModel model = (DefaultTableModel) videoTable.getModel();
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i);
    }/*w  ww .  java 2  s  .  c o  m*/
}

From source file:cz.moz.ctmanager.main.DetailsFrame.java

private void removeEmailButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeEmailButtonActionPerformed
    int selectedRow = emailTable.getSelectedRow();
    if (selectedRow == -1) {
        JOptionPane.showMessageDialog(this, "Nothing Selected", "Error Message", JOptionPane.ERROR_MESSAGE);
    } else {// www.j  av  a  2  s .  c o  m
        Object[] options = { "Are you Sure?" };
        int choice = JOptionPane.showConfirmDialog(this, options, "Are you Sure", 2);
        if (choice == 0) {
            DefaultTableModel newTableModel = (DefaultTableModel) emailTable.getModel();
            int selectedEmailID = (int) emailTable.getValueAt(emailTable.getSelectedRow(), 0);
            newTableModel.removeRow(selectedRow);
            emailsDao.removeEmail(selectedEmailID);
        }
    }
}

From source file:cz.moz.ctmanager.main.DetailsFrame.java

private void removePhoneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePhoneButtonActionPerformed
    int selectedRow = phoneTable.getSelectedRow();
    if (selectedRow == -1) {
        JOptionPane.showMessageDialog(this, "Nothing Selected", "Error Message", JOptionPane.ERROR_MESSAGE);
    } else {//www.j  ava  2 s  .  c  o m
        Object[] options = { "Are you Sure?" };
        int choice = JOptionPane.showConfirmDialog(this, options, "Are you Sure", 2);
        if (choice == 0) {
            DefaultTableModel newTableModel = (DefaultTableModel) phoneTable.getModel();
            int selectedPhoneID = (int) phoneTable.getValueAt(phoneTable.getSelectedRow(), 0);
            newTableModel.removeRow(selectedRow);
            phonesDao.removePhoneNumber(selectedPhoneID);
        }
    }
}

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 w w w.j ava  2s .  c o  m
}

From source file:HW3.java

public static void deleteAllRows(final DefaultTableModel model) {
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i);
    }/*from   w w w. ja  v a  2  s.co m*/
}

From source file:charitypledge.Pledge.java

public void DeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
    int[] rowDelete;
    rowDelete = PledgeViewTable.getSelectedRows();
    DefaultTableModel model = (DefaultTableModel) PledgeViewTable.getModel();

    for (int rows : rowDelete) {
        model.removeRow(PledgeViewTable.convertColumnIndexToModel(rows));
    }/*w w w .j  a  v  a  2s.  c o m*/
}

From source file:com.stanley.captioner.MainFrame.java

private void removeButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_removeButtonActionPerformed
{//GEN-HEADEREND:event_removeButtonActionPerformed
    int selectedRows[] = videoTable.getSelectedRows();
    if (selectedRows.length > 0) {
        DefaultTableModel model = (DefaultTableModel) videoTable.getModel();
        if (selectedRows.length > 0) {
            for (int i = selectedRows.length - 1; i >= 0; i--) {
                model.removeRow(selectedRows[i]);
            }// www. j  ava 2s  .c o  m
        }
    }
}