Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Adding a search bar

  1. #1
    david.ny is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default Adding a search bar

    Hello guys,
    So i have a java swing list in a j panel, this list contains a list of people with their names,
    on the top of that list i created a search bar, now i want the program once run, to search for me in the list of that people according to the name inserted in the search bar i created,
    my question is, as i am a very very beginner in java and netbeans, what is the source code i put for this specific bar in order to make it a search bar, thank you in advance

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Adding a search bar

    If you wish to search with the press of a JButton, then in the button's ActionListener have code that gets the JList's model (via getModel()), then use a for loop to iterate through the model getting each item with the model's getElementAt(int index) method, and checking if the element is a String that matches the one in your search bar's JTextField.

    You'll need to go through the Swing tutorials to find out how to code all of these things but with effort you will succeed.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Adding a search bar

    Starting a new thread instead of replying to a response on an earlier thread isn't the best way to continue to get help on a forum.

    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 03-25-2011, 12:50 AM
  2. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 02:42 AM
  3. Replies: 0
    Last Post: 10-29-2009, 10:28 AM
  4. Code for adding search function in an application
    By Avdhut in forum Threads and Synchronization
    Replies: 5
    Last Post: 03-03-2009, 11:15 AM
  5. Replies: 5
    Last Post: 08-26-2008, 03:43 PM

Posting Permissions

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