Results 1 to 11 of 11
  1. #1
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default Table filtering base on selection in a combobox

    How do I filter the display on the JXtable base on the selection from a combobox?
    Thank you!!

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Check out the JXTable tutorial.

  3. #3
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    Thank you dlorde for the response.

    I am experimenting with the following. This works with a regular expression.
    table.setFilters(new FilterPipeline(new Filter[] { new PatternFilter("A*", 0, 2) }));

    The problem is that how do I construct a regular expression with the text from a combobox. Or is it even possible?

    Please help!!

  4. #4
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by new2java2009 View Post
    The problem is that how do I construct a regular expression with the text from a combobox. Or is it even possible?
    Perhaps if you explained exactly what you need to do, I could suggest something. What relation has the text from the combobox to the table rows you want displayed or filtered?

  5. #5
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    I have a table that has 3 columns, with 0 & 1 visiable. The column 2 is invisable and it's only for the purpose of filtering.

    Column 2, the invisable column will contain one of the chooses from the combobox. When user makes a selection on the combo box, I want the table to filter the last column, and will only display rows with the last column containing the same text as the text in the combobox.

    Do I make myself clear? Thank you in advance.

  6. #6
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by new2java2009 View Post
    Do I make myself clear?
    Crystal ;)

    If you just want an exact text match, you should be able to use the relevant text as the regex in the pattern, e.g. assuming your combo box contains plain Strings:
    Java Code:
    combo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            String text = (String) combo.getSelectedItem();
            table.setFilters(new FilterPipeline(new Filter[] { new PatternFilter(text, 0, column)}));
        }
    });

  7. #7
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    Great! Thank you so much!
    I will give it a try, and come back to update you with the status.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    And if the combo box doesn't contain plain Strings, surround the text with the quotation metacharacters. See the documentation for Pattern.

    db

  9. #9
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    Thank yo also Derryl.

  10. #10
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Thumbs up

    It works!! Thank you so much for helping!!

  11. #11
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

Similar Threads

  1. Problem with ComboBox in a table
    By xyknight in forum New To Java
    Replies: 8
    Last Post: 04-25-2011, 04:05 AM
  2. how can i update my table with Jtextfield filtering?
    By sungirl in forum Advanced Java
    Replies: 4
    Last Post: 12-14-2010, 05:28 PM
  3. Replies: 6
    Last Post: 05-19-2010, 01:26 AM
  4. Replies: 1
    Last Post: 01-08-2010, 07:19 AM
  5. Jsf, Filtering Data In A Table
    By Freddie in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 05-11-2007, 01:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •