469,366 Members | 2,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

JTable - Filtering

144 100+
hi,

i read from the java.sun.com tutorial about JTable, and it says i can use the TableRowSorter, the method setFillsViewportHeight(boolean) of JTable and some other methods. but it seems that the class and the method is not available. i use jre 5. is it because that class and method available in different version?

how can i accomplish filtering in jre 5?

thx
Dec 13 '07 #1
16 5586
JosAH
11,448 Expert 8TB
hi,

i read from the java.sun.com tutorial about JTable, and it says i can use the TableRowSorter, the method setFillsViewportHeight(boolean) of JTable and some other methods. but it seems that the class and the method is not available. i use jre 5. is it because that class and method available in different version?

how can i accomplish filtering in jre 5?

thx
Upgrade to Java 1.6 for all those nice features; basically all you have to do is this:

Expand|Select|Wrap|Line Numbers
  1. yourTable.setAutoCreateRowSorter(true);
  2.  
and you get nice sorted tables according to a single column.

kind regards,

Jos
Dec 13 '07 #2
thesti
144 100+
Upgrade to Java 1.6 for all those nice features; basically all you have to do is this:

Expand|Select|Wrap|Line Numbers
  1. yourTable.setAutoCreateRowSorter(true);
  2.  
and you get nice sorted tables according to a single column.

kind regards,

Jos
thx Jos. with the auto create row sorter, can i have a table with filtering feature?

thx
Dec 13 '07 #3
JosAH
11,448 Expert 8TB
thx Jos. with the auto create row sorter, can i have a table with filtering feature?

thx
What sort of filtering? Either displaying a row or not type of filtering? If so, your
TableModel should be resposible for that. If not, I don't understand your question.

kind regards,

Jos
Dec 13 '07 #4
BigDaddyLH
1,216 Expert 1GB
thx Jos. with the auto create row sorter, can i have a table with filtering feature?
Sounds like to me your inner Java genie wants you to upgrade to 6 and use RowSorter. It has row filtering capabilities, too:

http://java.sun.com/developer/JDCTec.../tt1115.html#2
Dec 13 '07 #5
thesti
144 100+
well, this is a task that is given to me, and i dunno if i may use the 6 version. so, i try to do it with Java 5 if it's possible.

i don't really know how the sorting and filtering JTable works in Java. in fact i never use that sorting and filtering feature. what i know is that

i need in my program like a searching feature. user type something in a textfield and if the user click a button, the table will only display rows that has what the user typed as a substring of a particular column (specified before by the user from a combo box).

hope someone could help.

thx
Dec 13 '07 #6
JosAH
11,448 Expert 8TB
well, this is a task that is given to me, and i dunno if i may use the 6 version. so, i try to do it with Java 5 if it's possible.
I consider that a not-so-wise decision; if you don't know whether or not A, assuming
'not-A' is as silly as assuming the opposite 'A'. Why not ask your teacher first?

kind regards,

Jos
Dec 13 '07 #7
BigDaddyLH
1,216 Expert 1GB
You also haven't properly described your context. If the data is from a database, you could just do the filtering in a new query.
Dec 13 '07 #8
thesti
144 100+
it's from a file. haven't reach the database connection section

ok then, thx for your help.
Dec 14 '07 #9
JosAH
11,448 Expert 8TB
Better upgrade to Java 1.6; it'll only cost you ten minutes or so.

kind regards,

Jos
Dec 14 '07 #10
BigDaddyLH
1,216 Expert 1GB
Better upgrade to Java 1.6; it'll only cost you ten minutes or so.
I would check with your instructor first. Some are real bungholes about regulations and what students can and can't do. But when I was teaching, I would have shed tears of joy if any student showed this much initiative.
Dec 14 '07 #11
thesti
144 100+
hi, i've upgraded to jdk 6.0

so we filter the table using the TableRowSorter and from the TableRowSorter we set the row sorter. the method that i think i could use is the

RowFilter.regexFilter

but how can i specify which column to filter from the table?
thx
Dec 17 '07 #12
BigDaddyLH
1,216 Expert 1GB
but how can i specify which column to filter from the table?
thx
When one talks about the RowSorter and filtering, it's assumed you want to filter out rows. If it's columns you want to hide, that has nothing to do with the RowSorter. This is basic functionality that was already available in previous versions of JTable: get the table's TableColumnModel and use the method removeColumn to remove a column from view. You can also use the column model to do things like rearrange the order of the visible columns, set their preferred widths, etc...
Dec 17 '07 #13
thesti
144 100+
sorry english is not my native language. guess i described it wrong.

with RowSorter, i can get the guys whose first name starts with 'An' by filtering the first name right? what if i want to filter the guys whose last name starts with let's say 'Joh' or something. That's different field right, the fristname and the lastname.

so, how can i tell / specify which field is the RowSorter is filtering?

thx
Dec 17 '07 #14
BigDaddyLH
1,216 Expert 1GB
sorry english is not my native language. guess i described it wrong.

with RowSorter, i can get the guys whose first name starts with 'An' by filtering the first name right? what if i want to filter the guys whose last name starts with let's say 'Joh' or something. That's different field right, the fristname and the lastname.

so, how can i tell / specify which field is the RowSorter is filtering?

thx
Are you using the RowFilter factory method regexFilter? Have you read the API entry for it?

http://java.sun.com/javase/6/docs/ap...ing,%20int...)

Your answer may be there.
Dec 17 '07 #15
thesti
144 100+
thx BigDaddy.


so the RegexFilter takes the index of the table as the second argument. dunno before...

tq
Dec 18 '07 #16
BigDaddyLH
1,216 Expert 1GB
thx BigDaddy.


so the RegexFilter takes the index of the table as the second argument. dunno before...

tq
No problem If there's a big lesson to take away from this, it's always read the API. Read it for every class you use and especially for every method you call.
Dec 18 '07 #17

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Ben Munday | last post: by
1 post views Thread by asd | last post: by
1 post views Thread by raysaun | last post: by
reply views Thread by sivaprasad06 | last post: by
reply views Thread by nuria | last post: by
1 post views Thread by Andrea Sansottera | last post: by
1 post views Thread by onsir | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.