Results 1 to 10 of 10
  1. #1
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default Filter table model by data in specific column

    I implemented a row sorter in my application but found it's not what I was looking for. I have a table that contains ~40 columns and anywhere from 6 to 300 rows. I want the user to be able to select a column, then select from the unique values in that column and filter based on their selection.

    I have a combobox with the column headers, when selected it gets the unique values in that column and adds them to another combobox. When they select from the unique values, the row sorter searches for any column (string) which contains the value selected. I tried finding info on the net but got nothing concrete. I was going to write my own method but figured I would ask first. Maybe someone understands what I want and can help.

    Thanks.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Read the JTable API and follow the link to the section on the Swing tutorial on "How to Use Tables" for a working example. Its seems to me like all you need to do is change the filter every time a selection is made.

  3. #3
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    I've read that tutorial multiple times and I haven't seen anywhere where it shows how to filter a specific column's values. It says specifically that it searches for any row that contains the string from the filter field. Not a column in each row. That tutorial is actually where I got the code to generate my filter. But, like I said, if filters by row (entire row) I want to filter from a specific column.

    If someone looks for a unit's date shipped it's not only going to look in the date shipped column so it will return any row that contains that date in it which could be the date it moved into the status it's in, the date received, the date the PO was created or any number of other dates in the row. I need to isolate only the shipped dates.

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    It says specifically that it searches for any row that contains the string from the filter field.
    I don't see what anywhere in the tutorial. Post the exact quote.

    But, like I said, if filters by row (entire row) I want to filter from a specific column.
    Did you actually download the example and test it? Because if you did you would know that is NOT true. Did you take to the time to look at the API of the RowFilter to understand what the parameters mean. Spend time running the example and reading the API and you would have had the answer hours ago.
    Last edited by camickr; 10-29-2009 at 02:13 AM.

  5. #5
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    This is from the API
    "For example, a RowFilter associated with a JTable might only allow rows that contain a column with a specific string."..."For example, when a filter is associated with a JTable, an entry corresponds to a row"

    I interpreted the above as saying that if any column in the row contains a specific string, it will show it in the view.

    I downloaded the API but couldn't get it to work for some reason. The text areas and labels in the lower portion were all bunched together and I couldn't use them so I wasn't able to test it when I tried.

    I've read the tutorial again and read through the API and I still don't understand. All I am looking for is an example of how to do it. Just because I don't understand something that seems simple to you to doesn't mean I haven't read the information. I have been working on this since last night, after a day of testing it myself I gave up and asked for help. I put in my time and I just need some help on what commands I should look at, I'm not asking for anyone to write the code for me. I'm not intending to be mean if that is how it sounds (text doesn't portray spoken language well) I am just frustrated of trying different things for a day and when I ask for help it is implied that I didn't read the information just because I don't understand it. I understand where you are coming from as I've dealt with people who just want the answers and don't want to do any work but I truly have looked at the information and I just need help understanding it.

    As far as reading the parameters are you saying that this "int... indices" parameter in the static regexFilter method is where I would enter the column? If so, that isn't very clear in my opinion, if that is the case, it should say int ColumnIndex or something.

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    All I am looking for is an example of how to do it.
    And the tutorial has a working example, which is why I keep pointing you to the tutorial and the example.

    I downloaded the API but couldn't get it to work for some reason.
    Well, there are two source files to download.

    that isn't very clear in my opinion
    Which is why you download the example and play with it!

    As far as reading the parameters are you saying that this "int... indices" parameter in the static regexFilter method is where I would enter the column?
    Exactly, its a one character change, depending on the column you currenly have selected.

  7. #7
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    I downloaded both as stated in the comments of TableFilterDemo Still didn't work.

  8. #8
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Still didn't work.
    Not very descriptive of the problem.

  9. #9
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    I already posted the problem, the lower components (JLabels and JTextAreas) are all jammed in the left hand side of the GUI.

    My initial assumption was that it was something to do with this
    SpringUtilities.makeCompactGrid(form, 2, 2, 6, 6, 6, 6);

    but I couldn't figure out what it was. I'm still new at this so it's difficult for me to troubleshoot problems. I'll admit, I didn't spend much time on it because I wasn't aware that this model was a column specific filter.

  10. #10
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Well, I have no idea why it doesn't work for you, I've never use the SpringLayout. Try using another layout manager. Heck for a quick test just use a FlowLayout and layout all the components on a single line. It won't affect the filtering of the table.

Similar Threads

  1. Non-Editable Table Column
    By ld_pvl in forum AWT / Swing
    Replies: 6
    Last Post: 08-03-2009, 06:35 PM
  2. Add filter like MSExcel to SWT table object.
    By nitinkrgoyal in forum SWT / JFace
    Replies: 0
    Last Post: 03-20-2009, 09:57 AM
  3. How to implement a filter table
    By bridge8104 in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 12-31-2008, 08:46 PM
  4. Data from a model class won't show up in the table
    By ayampanggang in forum AWT / Swing
    Replies: 3
    Last Post: 11-27-2008, 08:20 PM
  5. Table model
    By Manfizy in forum NetBeans
    Replies: 4
    Last Post: 11-08-2008, 02:19 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
  •