Results 1 to 8 of 8
  1. #1
    hash004 is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default Searching Jtable

    Hi guys, I've created a jtable which is connected to a mysql database using the following tutorial A simple MySQL client in NB ( just the jtable is kept everything else from the tutorial is removed)

    What I was wondering is how can I search the jtable by typing the search in a jtextfield and pressing a jbutton to search.

    Any help would be appreciated.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default

    Read the API documentation for the TableRowSorter class and the RowFilter class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    hash004 is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Thanks for the reply. I was wondering is there a way to to the rowfilter but have it so when I'm typing something in it displays the result whiles doing so. kinda like google's instant search. hope you understand what I'm trying to say lol.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by hash004 View Post
    Thanks for the reply. I was wondering is there a way to to the rowfilter but have it so when I'm typing something in it displays the result whiles doing so. kinda like google's instant search. hope you understand what I'm trying to say lol.
    Sure, but you have to fiddle diddle a bit with the (probably?) JTextField because you have to grab its text as you type it in.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    hash004 is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Sure, but you have to fiddle diddle a bit with the (probably?) JTextField because you have to grab its text as you type it in.

    kind regards,

    Jos
    I'm totally new to this. Can you point me in the right direction to achieve this. thank you :)

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by hash004 View Post
    I'm totally new to this. Can you point me in the right direction to achieve this. thank you :)
    A JTextField has a text model that manages the text; it is called a Document; you can attach a listener to that Document that is called whenever the Document content changes. Read the API documentation for the relevant classes.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    hash004 is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    A JTextField has a text model that manages the text; it is called a Document; you can attach a listener to that Document that is called whenever the Document content changes. Read the API documentation for the relevant classes.

    kind regards,

    Jos
    thanks for pointing me in the right direction. I think I've got a rough idea on how to achieve this.
    Last edited by hash004; 08-14-2011 at 05:53 PM.

  8. #8
    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 Swing tutorial on "How to Use Tables" which has a working example of how to do this in the sorting/filtering section..

Similar Threads

  1. Searching still OK?
    By Jodokus in forum Suggestions & Feedback
    Replies: 2
    Last Post: 05-22-2011, 10:29 PM
  2. Searching
    By Harmesh Goyal in forum AWT / Swing
    Replies: 0
    Last Post: 03-02-2011, 02:36 PM
  3. Searching
    By peliukasss in forum Lucene
    Replies: 0
    Last Post: 04-07-2010, 01:05 AM
  4. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  5. searching
    By nalinda in forum New To Java
    Replies: 3
    Last Post: 12-06-2007, 02:56 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
  •