Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get data filter in JTable

 
tok chan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
tok chan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic