Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTable getting values of specific column

Tags:

java

swing

jtable

How could I get the values under specific column in JTable

example :

_________________________
| Column 1  | Column 2  |
________________________
|     1     | a         |
________________________
|     2     | b         |
________________________
|     3     | c         |
_________________________

How could I get the values under Column 1 that is [1, 2, 3] In the form of some data structure ( preferable array)?

like image 216
Mehari Mamo Avatar asked Feb 02 '14 12:02

Mehari Mamo


1 Answers

you can do something like this

ArrayList list = new ArrayList();
for(int i = 0;i<table.getModel().getRowCount();i++)
{
    list.add(table.getModel().getValueAt(i,0)); //get the all row values at column index 0
}
like image 198
lakshman Avatar answered Oct 14 '22 14:10

lakshman