| Author |
Get data filter in JTable
|
tok chan
Greenhorn
Joined: Jan 19, 2011
Posts: 2
|
|
Hi, i'm beginner in JAVA, need some help.
I have filtered my data in JTable, then i want to export data filtered to excel.
How to get data that i have filtered ?
my code filter JTable is like below :
String header[] = { "Name", "Country" };
Object[][] data = { { "Ryu", "Japan" }, { "Joong Ki", "Korea" },
{ "Hideaki", "Japan" }, { "Keanu", "English" } ,
{ "Watase Yuu", "Japan"} , {"Hyun Bin","Korea"}
};
jTable1.setModel(new DefaultTableModel(data, header) {
boolean[] canEdit = new boolean[]{false, false
};
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter("Korea", 1));
rf = RowFilter.andFilter(filters);
sorter = new TableRowSorter<TableModel>(jTable1.getModel());
sorter.setRowFilter(rf);
jTable1.setRowSorter(sorter);
Please help me...
Thanks,
Tokchan
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Welcome to the Ranch!
Use the JTable to get the values, not the TableModel. JTable.getValueAt etc use the row filter, row sorter et all. In other words, it will use exactly what is shown on the screen.
And please UseCodeTags next time.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
tok chan
Greenhorn
Joined: Jan 19, 2011
Posts: 2
|
|
Rob Spoor wrote:Welcome to the Ranch!
Use the JTable to get the values, not the TableModel. JTable.getValueAt etc use the row filter, row sorter et all. In other words, it will use exactly what is shown on the screen.
And please UseCodeTags next time.
Yes i know, but how to get data in that column ? because i want to export the data to file.
For example :
Line Name City
----------------------------------
1 A America
2 B Singapore
3 C Singapore
4 D Korea
5 E Japan
Then i filter City : Singapore
The Result is
Line Name City
----------------------------------
2 B Singapore
3 C Singapore
When i try to get with getvalueat, the data in table is not read filter data, but all data.
So i'm confused, how to get just only data filtered ?
Thanks,
tokchan
|
 |
 |
|
|
subject: Get data filter in JTable
|
|
|