JOsh
JOsh

Reputation: 167

Getting all the ID's from a specific column automatically (i.e. not having to select a row) in a JTable

I would like,as the title suggests, to be able to get all the values in an ID column from a JTable without the user actually selecting a row (and thus ID).Lets say there are two results in the JTable, that means there are two items in the ID column. Is there a way that I extract these values automatically.

Upvotes: 0

Views: 41

Answers (1)

trashgod
trashgod

Reputation: 205835

Much depends on your goal, but you can

  • Traverse the TableModel, invoking getColumnClass() for each column; use getValueAt() to examine the value for a particular row.

    DefaultTableModel model = new DefaultTableModel();
    …
    for (int col = 0; col < model.getColumnCount(); col++) {
        Class type = model.getColumnClass(col);
    }
    
  • Use the methods of DatabaseMetaData & ResultSetMetaData to get the details of a relation's attributes, before inserting the data into the TableModel.

Upvotes: 1

Related Questions