[英]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. 正如标题所示,我希望能够从JTable中获取ID列中的所有值,而无需用户实际选择一行(并因此选择ID)。假设JTable中有两个结果,那意味着是ID列中的两项。 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; 遍历TableModel
,为每列调用getColumnClass()
; use getValueAt()
to examine the value for a particular row. 使用getValueAt()
检查特定行的值。
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
. 在将数据插入TableModel
之前 ,使用DatabaseMetaData
和ResultSetMetaData
的方法ResultSetMetaData
关系属性的详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.