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:org.jas.gui.MainWindow.java

private void deleteALLRows(JTable descriptionTable) {
    DefaultTableModel model = (DefaultTableModel) descriptionTable.getModel();
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i);//from ww  w.  ja v a  2 s  . c  o  m
    }
}

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   w  w  w .  j  a  v  a  2 s . com
    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: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  ww  .ja va 2  s  .  c o  m*/
    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:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

private void removeSelection(boolean ask) {
    jideRetimeTabbedPane.setSelectedIndex(1);
    int[] selectedRows = jResultTable.getSelectedRows();
    if (selectedRows == null || selectedRows.length < 1) {
        showInfo("Keine Eintrge ausgewhlt");
        return;/*from   w  ww  . j  a  va2 s.c  o m*/
    }

    if (!ask || JOptionPaneHelper.showQuestionConfirmBox(this,
            "Willst du "
                    + ((selectedRows.length == 1) ? "den gewhlten Eintrag " : "die gewhlten Eintrge ")
                    + "wirklich lschen?",
            "Lschen", "Nein", "Ja") == JOptionPane.YES_OPTION) {
        DefaultTableModel model = (DefaultTableModel) jResultTable.getModel();
        int numRows = selectedRows.length;
        for (int i = 0; i < numRows; i++) {
            model.removeRow(jResultTable.convertRowIndexToModel(jResultTable.getSelectedRow()));
        }
        showSuccess("Eintrge gelscht");
    }
}

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

private void updateSoilInfoAndSoilLayerInfo(int index) {

    // Update the data in the table base on the index 0
    SoilData soilData = utils.getSoilData();
    String key = (String) soilFileListCombo.getItemAt(index);
    if (key == null) {
        return;/*from  ww w . ja va2 s.co  m*/
    }

    soilNameCombo.removeAllItems();

    ArrayList<Soil> soilList = soilData.getSoilsFromFile(key);
    if (soilList.size() > 0) {

        for (Soil soil : soilList) {
            soilNameCombo.addItem(soil.getName());
        }

        DefaultTableModel model = (DefaultTableModel) soilTable.getModel();
        int row = model.getRowCount();
        for (int i = 0; i < row; i++) {
            model.removeRow(0);

        }

        int soilIndex = soilNameCombo.getSelectedIndex();
        Soil soil = soilList.get(soilIndex == -1 ? 0 : soilIndex);
        DU = soil.getDU();
        WCL = soil.getWCL();
        WCU = soil.getWCU();
        WC = soil.getWC();
        NL = soil.getNL();
        SNAME = soil.getName();
        utils.setDefaultSoil(soil);

        for (int i = 0; i < soil.getNL(); i++) {
            Object[] vec = new Object[4];
            vec[0] = i + 1;
            vec[1] = soil.getDU()[i];
            vec[2] = soil.getWC()[i];
            DecimalFormat df = new DecimalFormat("####0.000");
            vec[3] = df.format(WCU[i] - WCL[i]);
            model.addRow(vec);
        }
    }
}

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

private void toogleStateOfControls(java.awt.event.ActionEvent evt) {

    isInitializing = true;//  w w  w .  j ava  2  s . c  o m
    boolean isFileLocationSelected = jRadioButtonSavedLocation.isSelected();
    boolean isFileSelected = jRadioFile.isSelected();
    boolean isKeyboardEnabled = jRadioKeyboard.isSelected();

    jButtonMap.setEnabled(isFileLocationSelected);
    soilFileListCombo.setEnabled(isFileLocationSelected);
    showSoilDataButton.setEnabled(isFileSelected || isFileLocationSelected);
    soilListBox.setEnabled(isFileSelected);
    waterholdcapacityBox.setEnabled(!isKeyboardEnabled);

    soilNameCombo.setEnabled(isFileLocationSelected);
    soilNameText.setEnabled(isKeyboardEnabled);
    soilTextureText.setEnabled(isKeyboardEnabled);
    NLComboBox.setEnabled(isKeyboardEnabled);
    soilTable.setEnabled(isKeyboardEnabled || isFileLocationSelected);
    soilNameCombo.setEditable(isKeyboardEnabled);
    jButtonRefresh.setEnabled(isFileLocationSelected);

    errorLabel.setVisible(false);
    wcErrorLabel.setVisible(false);

    DefaultTableModel model = (DefaultTableModel) soilTable.getModel();
    int row = model.getRowCount();
    for (int i = 0; i < row; i++) {
        model.removeRow(0);
    }

    // Update the list of soils in the soil name combo box.
    if (jRadioButtonSavedLocation.isSelected()) {

        if (utils.getSoilData() == null) {
            utils.setSoilData(new SoilData());
        }

        if (soilFileListCombo.getItemCount() > 0) {
            soilFileListCombo.removeAllItems();
        }

        soilFileListCombo.removeAllItems();

        if (isFileLocationSelected) {
            files = null;
            files = getListOfDataFiles();
            int i = 0;
            for (File f : files) {
                String key = f.getName();
                key = key.trim();
                soilFileListCombo.addItem(f.getName());
                updateSoilDataBaseOnSoilFileSelection(i++);
            }
        }
        //updateSoilDataBaseOnSoilFileSelection (0);
        updateSoilInfoAndSoilLayerInfo(0);
        prevButtonSelectedSavedLocation = true;
    }

    int index = isFileSelected ? 0 : (isFileLocationSelected ? 1 : 2);
    //System.out.println ("\n\n ToogleSelection ---- " + index);        
    waterholdcapacityBox.setSelectedIndex(waterHoldSelectedItemIndex[index]);
    isInitializing = false;

}

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

private void soilNameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_soilNameComboActionPerformed

    // TODO add your handling code here:
    if (isInitializing)
        return;//from  w  w w.jav  a  2 s. co  m

    int index = soilNameCombo.getSelectedIndex();
    if (index == -1)
        return;
    //index = index ==-1? 0 : index;
    SoilData soilData = utils.getSoilData();
    String key = (String) soilFileListCombo.getSelectedItem();
    key = key.trim();
    ArrayList<Soil> soilList = soilData.getSoilsFromFile(key);

    if (soilList.size() > 0) {

        if (index == -1) {

            // TODO add your handling code here:
            DefaultTableModel model = (DefaultTableModel) soilTable.getModel();
            int row = model.getRowCount();
            for (int i = 0; i < row; i++) {
                model.removeRow(0);
            }
            index = 0;
            Soil soil = soilList.get(index);
            for (int i = 0; i < soil.getNL(); i++) {
                Object[] vec = new Object[4];
                vec[0] = i + 1;
                vec[1] = soil.getDU()[i];
                vec[2] = soil.getWC()[i];
                vec[3] = soil.getWCU()[i] - soil.getWCL()[i];
                model.addRow(vec);

            }
        } else {

            // This is to take the backup of the data so that I can 

            //Soil soil = soilList.get(selectedSoilIndex);
            DefaultTableModel model = (DefaultTableModel) soilTable.getModel();

            if (prevSoil != null) {
                for (int i = 0; i < model.getRowCount(); i++) {
                    prevSoil.getDU()[i] = (Double) model.getValueAt(i, 1);
                    prevSoil.getWC()[i] = (Double) model.getValueAt(i, 2);
                }
            }

            int row = model.getRowCount();
            for (int i = 0; i < row; i++) {
                model.removeRow(0);
            }

            Soil soil = soilList.get(index);

            DU = soil.getDU();
            WCL = soil.getWCL();
            WCU = soil.getWCU();
            WC = soil.getWC();
            NL = soil.getNL();
            SNAME = soil.getName();
            utils.setDefaultSoil(soil);

            for (int i = 0; i < soil.getNL(); i++) {
                Object[] vec = new Object[4];
                vec[0] = i + 1;
                vec[1] = soil.getDU()[i];
                vec[2] = soil.getWC()[i];
                vec[3] = (WCU[i] - WCL[i]);
                model.addRow(vec);

            }

            prevSoil = soil;
        }

    }
    //selectedSoilIndex = index;
}

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

private void showXLS(JTextField txtFileDirectory, JTable tablePreview)
        throws FileNotFoundException, IOException {
    DefaultTableModel tableModel = new DefaultTableModel();
    File fileName = new File(txtFileDirectory.getText());
    FileInputStream inputStream = new FileInputStream(fileName);
    HSSFWorkbook workBook = new HSSFWorkbook(inputStream);
    HSSFSheet sheet = workBook.getSheetAt(0);

    int rowValue = sheet.getLastRowNum() + 1;
    int colValue = sheet.getRow(0).getLastCellNum();
    String[][] data = new String[rowValue][colValue];
    String[] colName = new String[colValue];
    for (int i = 0; i < rowValue; i++) {
        HSSFRow row = sheet.getRow(i);/* w  w  w.  j  av  a  2  s  . c o  m*/
        for (int j = 0; j < colValue; j++) {
            HSSFCell cell = row.getCell(j);
            int type = cell.getCellType();
            Object returnCellValue = null;
            if (type == 0) {
                returnCellValue = cell.getNumericCellValue();
            } else if (type == 1) {
                returnCellValue = cell.getStringCellValue();
            }

            data[i][j] = returnCellValue.toString();
        }
    }

    for (int i = 0; i < colValue; i++) {
        colName[i] = data[0][i];
    }

    tableModel = new DefaultTableModel(data, colName);
    tablePreview.setModel(tableModel);
    tableModel.removeRow(0);
}

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

private void showXLSX(JTextField txtFileDirectory, JTable tablePreview)
        throws FileNotFoundException, IOException {
    DefaultTableModel tableModel = new DefaultTableModel();
    File fileName = new File(txtFileDirectory.getText());
    FileInputStream inputStream = new FileInputStream(fileName);
    XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
    XSSFSheet sheet = workbook.getSheetAt(0);

    int rowValue = sheet.getLastRowNum() + 1;
    int colValue = sheet.getRow(0).getLastCellNum();
    String[][] data = new String[rowValue][colValue];
    String[] colName = new String[colValue];
    for (int i = 0; i < rowValue; i++) {
        XSSFRow row = sheet.getRow(i);/* ww w.j a  va2  s .co m*/
        for (int j = 0; j < colValue; j++) {
            XSSFCell cell = row.getCell(j);
            int type = cell.getCellType();
            Object returnCellValue = null;
            if (type == 0) {
                returnCellValue = cell.getNumericCellValue();
            } else if (type == 1) {
                returnCellValue = cell.getStringCellValue();
            }

            data[i][j] = returnCellValue.toString();
        }
    }

    for (int i = 0; i < colValue; i++) {
        colName[i] = data[0][i];
    }

    tableModel = new DefaultTableModel(data, colName);
    tablePreview.setModel(tableModel);
    tableModel.removeRow(0);
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java

private void createToolbar() {
    ActionListener addAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultTableModel model = (DefaultTableModel) formatSwitchTbl.getModel();
            DataObjSwitchFormatter fmt = formatContainer.getSelectedFormatter();
            DataObjDataFieldFormat fld = new DataObjDataFieldFormat();
            fmt.add(fld);/* w  ww  . ja va 2s.c  om*/
            model.addRow(new Object[] { fld.getValue(), fld, ellipsisButtonLabel });
            setHasChanged(true);
            enableUIControls();
        }
    };

    ActionListener delAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int formatColumn = formatSwitchTbl.getColumn(DISPLAY_FORMAT_COL).getModelIndex();
            DefaultTableModel model = (DefaultTableModel) formatSwitchTbl.getModel();
            DataObjSwitchFormatter fmt = formatContainer.getSelectedFormatter();
            int[] rows = formatSwitchTbl.getSelectedRows();
            // sort rows in reverse order otherwise removing the first rows
            // will mess up with the row numbers
            Integer[] intRows = new Integer[rows.length];
            for (int i = 0; i < rows.length; ++i) {
                intRows[i] = new Integer(rows[i]);
            }
            Arrays.sort(intRows, Collections.reverseOrder());
            for (int currentRow : intRows) {
                fmt.remove((DataObjDataFieldFormatIFace) model.getValueAt(currentRow, formatColumn));
                model.removeRow(currentRow);
            }
            formatSwitchTbl.clearSelection();
            setHasChanged(true);
            enableUIControls();
        }
    };

    controlPanel = new EditDeleteAddPanel(null, delAL, addAL);
    controlPanel.getAddBtn().setEnabled(true);
}