0

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);
  }
...
}

Edited by LianaN: n/a

2
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by LianaN
1

from my resources

public void deleteData() {
        int rows = getRowCount();
        if (rows == 0) {
            return;
        }
        cache.clear();
        fireTableRowsDeleted(0, rows - 1);
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.