my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Get data filter in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Get data filter in JTable" Watch "Get data filter in JTable" New topic
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: 19653
    
  18

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 - OCEEJBD 6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get data filter in JTable
 
Similar Threads
JTable RowFilter by row number
Problem Updating Content Of JTable
JTable rowFilter - is case insensitive possible?
JTable adding a RowFilter can no longer add to the table get invalid range?
RowFilter dont show rows in JTable