• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get data filter in JTable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic