954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to empty empty my JTable (AbstractTableModel)?

How could I empty my JTable (AbstractTableModel)? If I run tableModel.deleteData(); , then the message "0 >= 0" appears. Thanks!

class QueryTableModel extends AbstractTableModel {
  Vector cache; // will hold String[] objects
  int colCount;
  String[] headers;
  String url; String databasename;
  String login; String pass;
  Connection db;
  static Statement statement;

  public QueryTableModel(String url, String databasename, String login, String pass) {
    cache = new Vector();
    initDB(url, databasename, login, pass);
  }

  public static Statement getStatement() {
      return statement;
  }

  @Override
  public String getColumnName(int i) {
    return headers[i];
  }

  public int getColumnCount() {
    return colCount;
  }

  @Override
  public Class getColumnClass(int col) {
    return getValueAt(0, col).getClass();
  }

  @Override
  public int getRowCount() {
    return cache.size();
  }

@Override
  public Object getValueAt(int row, int col) {
    Object str = ((Object[]) cache.elementAt(row))[col];
    if (str != null)
        return str;
    else return "";
  }

  public void deleteData() {
    cache.clear();
    fireTableChanged(null);
  }
...
}
LianaN
Posting Whiz in Training
285 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

from my resources

public void deleteData() {
        int rows = getRowCount();
        if (rows == 0) {
            return;
        }
        cache.clear();
        fireTableRowsDeleted(0, rows - 1);
    }
quuba
Posting Pro
573 posts since Nov 2008
Reputation Points: 123
Solved Threads: 106
 

Thank you a lot! It works!

LianaN
Posting Whiz in Training
285 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: