Skip to main content

JXSearchPanel with JXTable - Filtering problem

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2013-04-25

I'm having some problems in trying to use a JXSearchPanel with a JXTable.
The problem is that I can't relate both components, and the examples I've seen on the net are not working with swingx 1.6.
I add a simple code.

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.jdesktop.swingx.JXSearchPanel;
import org.jdesktop.swingx.JXTable;
public class FiltratingTable {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Filtrating on JXTable");
    Object rows[][] = { { "A", "About", 44.36 }, { "B", "Boy", 44.84 }, { "C", "Cat", 463.63 },
        { "D", "Day", 27.14 }, { "E", "Eat", 44.57 }, { "F", "Fail", 23.15 },
        { "G", "Good", 4.40 }, { "H", "Hot", 24.96 }, { "I", "Ivey", 5.45 },
        { "J", "Jack", 49.54 }, { "K", "Kids", 280.00 } };
    String columns[] = { "Symbol", "Name", "Price" };
    TableModel model = new DefaultTableModel(rows, columns) {
    public Class getColumnClass(int column) {
        Class returnValue;
        if ((column >= 0) && (column < getColumnCount())) {
          returnValue = getValueAt(0, column).getClass();
        } else {
          returnValue = Object.class;
        return returnValue;
    final JXTable table = new JXTable(model);
    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    JScrollPane pane = new JScrollPane(table);
    frame.getContentPane().add(pane, BorderLayout.CENTER);
    JPanel panel = new JPanel(new BorderLayout());
  JXSearchPanel searchPanel = new JXSearchPanel();
    frame.getContentPane().add(panel, BorderLayout.NORTH);
    frame.setSize(642, 323);

Do you have any suggestions?
Thank's a lot,


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-12

From this example, you are not doing anything with that searchPanel. Somehow, it should be connected to the table/model or you should do something with its events...

Can't tell you more than that, I do not know this component.

You want to use JXSearchPanel to filter the rows ?

Joined: 2013-04-25

Yes I want to use JXSearchPanel to filter the rows, and as you've said I need to somehow connect the model to the searchPanel, but don't know how to do it.
I've searched in the documentation available but couldn't find anything that worked.