简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM