Java Code Examples for javax.swing.table.DefaultTableModel#removeRow()

The following examples show how to use javax.swing.table.DefaultTableModel#removeRow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskManagerTabPanel.java    From moa with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Clean the tables
 */
public void cleanTables() {
    try {
        DefaultTableModel algModel = (DefaultTableModel) jTableAlgorithms.getModel();
        DefaultTableModel strModel = (DefaultTableModel) jTableStreams.getModel();
        int rows = jTableAlgorithms.getRowCount();
        int srow = jTableStreams.getRowCount();
        int trow = this.taskList.size();
        for (int i = 0; i < rows; i++) {
            algModel.removeRow(0);
        }
        for (int i = 0; i < srow; i++) {
            strModel.removeRow(0);
        }
        for (int i = 0; i < trow; i++) {
            this.taskList.remove(0);
        }
        this.taskTableModel.fireTableDataChanged();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error al limpiar la tabla.");
    }
}
 
Example 2
Source File: SecurityRolesEditorPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
    int[] selectedRows = selectedRolesTable.getSelectedRows();
    DefaultTableModel allRolesTableModel = (DefaultTableModel) allRolesTable.getModel();
    DefaultTableModel selectedRolesTableModel = (DefaultTableModel) selectedRolesTable.getModel();
    
    // Get the list of selected role names
    for (int i = 0; i < selectedRows.length; i++) {
        String roleName = (String) selectedRolesTableModel.getValueAt(selectedRows[i], 0);
        allRolesTableModel.addRow(new Object[] {roleName});
    }
    
    // Now remove the selected rows from the allRolesTable
    for (int i = selectedRows.length-1; i >=0; i--) {
        selectedRolesTableModel.removeRow(selectedRows[i]);
    }
}
 
Example 3
Source File: TimeComponentPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void changeRow(Object fo, String key) {
    Integer row = key2RowNumber.get(key);
    DefaultTableModel model = (DefaultTableModel) times.getModel();
    
    if (row != null) {
        model.removeRow(row);
    }
    
    TimesCollectorPeer.Description desc = TimesCollectorPeer.getDefault().getDescription(fo, key);
    
    if (desc == null) {
        return ;
    }
    
    if (row == null) {
        key2RowNumber.put(key, row = model.getRowCount());
    }
    
    model.insertRow(row, new Object[] {desc.getMessage(), desc.getTime()});
}
 
Example 4
Source File: EndpointsButton.java    From attack-surface-detector-burp with Mozilla Public License 2.0 6 votes vote down vote up
private void fillEndpointsToTable(EndpointDecorator[] decorators)
{
    int count = 0;
    JTable endpointTable = BurpPropertiesManager.getBurpPropertiesManager().getEndpointsTable();
    DefaultTableModel dtm = (DefaultTableModel)endpointTable.getModel();
    while(dtm.getRowCount() > 0)
        dtm.removeRow(0);

    for (EndpointDecorator decorator : decorators)
    {
        Endpoint.Info endpoint = decorator.getEndpoint();
        boolean hasGet = false;
        boolean hasPost = false;
        String method = endpoint.getHttpMethod();
        if(method.toString().equalsIgnoreCase("post"))
            hasPost = true;
        else if (method.toString().equalsIgnoreCase("get"))
            hasGet = true;
        dtm.addRow(new Object[]{endpoint.getUrlPath(), endpoint.getParameters().size(), hasGet, hasPost,
                (decorator.getStatus() == EndpointDecorator.Status.NEW || decorator.getStatus() == EndpointDecorator.Status.CHANGED), decorator});
        count++;
    }
    JLabel countLabel = BurpPropertiesManager.getBurpPropertiesManager().getCountLabel();
    countLabel.setVisible(true);
    countLabel.setText("Total Endpoints Detected: " + count);
}
 
Example 5
Source File: SummaryTab.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Clean the tables
 */
public void cleanTables() {
    try {
        DefaultTableModel algModel = (DefaultTableModel) jTableAlgoritms.getModel();
        DefaultTableModel strModel = (DefaultTableModel) jTableStreams.getModel();
        DefaultTableModel measureModel = (DefaultTableModel) jTableMeasures.getModel();
        int rows = jTableAlgoritms.getRowCount();
        int srow = jTableStreams.getRowCount();
        int trow = this.jTableMeasures.getRowCount();
        for (int i = 0; i < rows; i++) {
            algModel.removeRow(0);
        }
        for (int i = 0; i < srow; i++) {
            strModel.removeRow(0);
        }
        for (int i = 0; i < trow; i++) {
            this.measureModel.removeRow(0);
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error cleaning the table.");
    }
    jButtonSummarize.setEnabled(false);
}
 
Example 6
Source File: AnalyzeTab.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tables of algorithms and datasets are cleaned.
 */
public void cleanTables() {
    try {
        DefaultTableModel algModel = (DefaultTableModel) jTableAlgoritms.getModel();
        DefaultTableModel strModel = (DefaultTableModel) jTableStreams.getModel();
        int rows = jTableAlgoritms.getRowCount();
        int srow = jTableStreams.getRowCount();
        for (int i = 0; i < rows; i++) {
            algModel.removeRow(0);
        }
        for (int i = 0; i < srow; i++) {
            strModel.removeRow(0);
        }

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error cleaning the table.");
    }
}
 
Example 7
Source File: DriverSettings.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void removeCapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeCapActionPerformed
    int[] rows = capTable.getSelectedRows();
    if (rows != null) {
        DefaultTableModel model = (DefaultTableModel) capTable.getModel();
        for (int i = rows.length - 1; i >= 0; i--) {
            model.removeRow(rows[i]);
        }
    }
}
 
Example 8
Source File: TimeComponentPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void fillTimeTable() {
    Reference ref = (Reference)jList1.getSelectedValue();
    Object fo = ref == null ? null : ref.get();
    
    // clear the table
    DefaultTableModel model = (DefaultTableModel) times.getModel();
    while (model.getRowCount() > 0) {
        model.removeRow(0);
    }
    key2RowNumber.clear();
    
    if (fo == null) return;
    
    Collection<String> keys = TimesCollectorPeer.getDefault().getKeysForFile(fo);
    for (int i = 0; i < 10; i++) {
        try {
            synchronized(keys) {
                for (String key : keys) {
                    changeRow(fo, key);
                }
                return;
            }
        } catch (ConcurrentModificationException ex) {
            LOG.log(Level.INFO, "Retry " + i, ex);
        }
    }
}
 
Example 9
Source File: TableInCellButtonColumn.java    From WePush with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    int isDelete = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMessagePanel(), "确定移除?", "请确认",
            JOptionPane.YES_NO_OPTION);
    if (isDelete == JOptionPane.YES_OPTION) {
        fireEditingStopped();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.removeRow(table.getSelectedRow());
    }
}
 
Example 10
Source File: CustomizerCompile.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void removeOptionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeOptionButtonActionPerformed
    DefaultTableModel model = (DefaultTableModel) processorOptionsTable.getModel();
    int[] rows = processorOptionsTable.getSelectedRows();
    for(int i = rows.length - 1 ; i >= 0 ; i--) {
        model.removeRow(rows[i]);
    }
    if (model.getRowCount() > 0) {
        // Select reasonable row
        int selectedIndex = rows[rows.length - 1] - rows.length  + 1;
        if ( selectedIndex > model.getRowCount() - 1) {
            selectedIndex = model.getRowCount() - 1;
        }
        processorOptionsTable.setRowSelectionInterval(selectedIndex, selectedIndex);
    }
}
 
Example 11
Source File: TablePanel.java    From CodeGen with MIT License 5 votes vote down vote up
/**
 * 删除
 */
private void removeAction() {
    int selectedRow = fieldTable.getSelectedRow();
    if (selectedRow != -1) {
        DefaultTableModel tableModel = (DefaultTableModel) fieldTable.getModel();
        tableModel.removeRow(selectedRow);
    }
    if (fieldTable.getRowCount() > 0) {
        fieldTable.setRowSelectionInterval(0, 0);
    }
}
 
Example 12
Source File: SwingUtil.java    From Repeat with Apache License 2.0 5 votes vote down vote up
/**
 * Remove the last rows of the table that do not contain any data
 * @param table the table with rows to be removed
 */
public static int removeLastRowsTable(JTable table) {
	if (table.getRowCount() == 0) {
		return 0;
	}

	DefaultTableModel model = (DefaultTableModel) table.getModel();
	int count = 0;

	while (true) {
		boolean remove = true;
		for (int i = 0; i < table.getColumnCount(); i++) {
			String data = getStringValueTable(table,
					table.getRowCount() - 1, i);
			if (!data.equals("")) {
				remove = false;
				break;
			}
		}

		if (remove) {
			count++;
			model.removeRow(model.getRowCount() - 1);
		} else {
			break;
		}
	}

	return count;
}
 
Example 13
Source File: MainMenu.java    From JavaBankApp with GNU General Public License v2.0 5 votes vote down vote up
private void reloadTable() {
    DefaultTableModel model = (DefaultTableModel) accountTable.getModel();
    // Deletes the rows from the highest index downwards, since deleting 
    // from index 0 would shift all remaining rows to a lower index
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i); 
    }
    for (Customer c : bank.getCustomers()) {
        addCustomerToTable(c);
    }
}
 
Example 14
Source File: TableInCellButtonColumn.java    From MooTool with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    int isDelete = JOptionPane.showConfirmDialog(App.mainFrame, "确定移除?", "请确认",
            JOptionPane.YES_NO_OPTION);
    if (isDelete == JOptionPane.YES_OPTION) {
        fireEditingStopped();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.removeRow(table.getSelectedRow());
    }
}
 
Example 15
Source File: AbstractTableAdapter.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void adjustTableModel() {
    final DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    final Object value = getBinding().getPropertyValue();
    if (value instanceof Object[]) {
        final Object[] items = (Object[]) value;
        // 1. add missing rows to model
        for (int i = tableModel.getRowCount(); i < items.length; i++) {
            tableModel.addRow((Object[]) null);
        }
        // 2. remove redundant rows from model
        for (int i = items.length; i < tableModel.getRowCount(); i++) {
            tableModel.removeRow(i);
        }
        // 3. update cell values
        for (int i = 0; i < items.length; i++) {
            final Object item = items[i];
            final Field[] fields = item.getClass().getDeclaredFields();
            for (int k = 0; k < fields.length; k++) {
                final Field field = fields[k];
                final boolean accessible = field.isAccessible();
                if (!accessible) {
                    field.setAccessible(true);
                }
                try {
                    Vector dataVector = tableModel.getDataVector();
                    Vector row = (Vector)dataVector.elementAt(i);
                    // 1. add missing columns to row
                    for (int l = row.size(); l < fields.length; l++) {
                        row.add(null);
                    }
                    // 2. remove redundant columns from row
                    for (int l = fields.length; l < row.size(); l++) {
                        row.remove(l);
                    }

                    tableModel.setValueAt(field.get(item), i, k);
                } catch (IllegalAccessException e) {
                    // ignore
                }
                if (!accessible) {
                    field.setAccessible(false);
                }
            }
        }
    }
}
 
Example 16
Source File: XTable.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void emptyTable() {
    DefaultTableModel model = (DefaultTableModel)getModel();
    while (model.getRowCount()>0)
        model.removeRow(0);
}
 
Example 17
Source File: XTable.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void emptyTable() {
    DefaultTableModel model = (DefaultTableModel)getModel();
    while (model.getRowCount()>0)
        model.removeRow(0);
}
 
Example 18
Source File: SettingsDialog.java    From megabasterd with GNU General Public License v3.0 4 votes vote down vote up
private void remove_mega_account_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove_mega_account_buttonActionPerformed

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

        int selected = mega_accounts_table.getSelectedRow();

        while (selected >= 0) {

            String email = (String) model.getValueAt(mega_accounts_table.convertRowIndexToModel(selected), 0);

            _deleted_mega_accounts.add(email);

            model.removeRow(mega_accounts_table.convertRowIndexToModel(selected));

            selected = mega_accounts_table.getSelectedRow();
        }

        mega_accounts_table.clearSelection();

        if (model.getRowCount() == 0) {

            remove_mega_account_button.setEnabled(false);
        }

    }
 
Example 19
Source File: XTable.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void emptyTable() {
    DefaultTableModel model = (DefaultTableModel)getModel();
    while (model.getRowCount()>0)
        model.removeRow(0);
}
 
Example 20
Source File: XTable.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void emptyTable() {
    DefaultTableModel model = (DefaultTableModel)getModel();
    while (model.getRowCount()>0)
        model.removeRow(0);
}