Skip to main content

Use JXSearchPanel with JTable

6 replies [Last post]
delildor
Offline
Joined: 2010-08-31

Hello,

I' have implement my code like this for the moment to be able to filter a jTable :

TableRowSorter sorter = new TableRowSorter(tableModel);
jTable1.setRowSorter(sorter);
Pattern pattern = jXSearchPanel1.getPattern();
if(pattern != null)
sorter.setRowFilter(RowFilters.regexFilter(pattern, 0))

But how we can executed this code when someone put text on the jxsearchfield ?

Best regards,

P.S : Sorry for my english, i'm french

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
delildor
Offline
Joined: 2010-08-31

No one can help me ?

kschaefe
Offline
Joined: 2006-06-08

Give people a little bit to read and respond. We're not all on the same time zone as you.

Add a property change listener for "pattern" to the JXSearchPanel's pattern model. This will keep you in sync with the latest changes to the search.

Karl

delildor
Offline
Joined: 2010-08-31

Thank you for your answer,

Do you have an example of this implementation ?

kschaefe
Offline
Joined: 2006-06-08

No, I don't. Here's one that I just made up completely on the fly:
[code]JXTable table = ...
JXSearchPanel panel = ...
panel.getPatternModel().addPropertyChangeListener("pattern", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
table.setRowFilter(RowFilters.regexFilter(pattern, 0));
}
}[/code]

There's a little more work with a plain JTable, such as getting the RowSorter because it does not support direct filtering.

Karl

delildor
Offline
Joined: 2010-08-31

Thank you to answer but i don't have the method getpatternModel(). What swingx library do you use ?

kschaefe
Offline
Joined: 2006-06-08

Yeah, that's protected. Heh, shows me that I should watch where I build my test cases.

Try the following (untested):
[code]JXTable table = ...
JXSearchPanel panel = ...
panel.addPatternMatcher(new PatternMatcher() {
public Pattern getPattern() { }

public void setPattern(Pattern pattern) {
table.setRowFilter(RowFilters.regexFilter(pattern, 0));
}
}[/code]

Karl