The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Search GUI: using JTextField vs. JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Search GUI: using JTextField vs. JComboBox" Watch "Search GUI: using JTextField vs. JComboBox" New topic

Search GUI: using JTextField vs. JComboBox

Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Hello All,
I am thinking about what is the appropriate way to provide GUI to user for searching.
I see two possibilities:
1. with JComboBox
2. with JTextField
Both of them have positive and negative sides.
With ComboBox user cannot enter the bad data, it simplifies the search. But the choice of the correct item will be complicated by having too many items in the database. Accordingly to the assignment the database file will be used also by another program. And if a new record will be added from another program to the database the combobox will not have the actual data.
With TextField we will have always the search of the actual data. But user can enter the bad data and this complicates the search.
My favorit is the second one TextField. But I am not sure.

How do you think what is the best way? ComboBor or TextFields?
Could you help me to choose the correct way?
Thanks a lot!

SCJP 1.4<br />SCJD 1.4 (in progress)
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
I don't consider selecting a subset using a combobox to be searching the database.
I doubt Sun considers it searching either...

Cleverson Schmidt
Ranch Hand

Joined: Feb 17, 2004
Posts: 55
Hi Olena,

Why don't you provide both ways by giving the user an editable JComboBox? This way, the user will be able to both select a value from the list and type his own.

Best Regards
Cleverson Schmidt
David Abramowicz
Ranch Hand

Joined: Dec 10, 2004
Posts: 56

Having a JComboBox would involve one of these three poor options (in my humble opinion) :

- loading all possible search values at app start-up and never refreshing them

- loading all possible values every time a user clicks a search field

- having a complex caching mechanism that is somewhere in between the two options above

The third option I could live with, but it seems much too complex for this assignment.

Instead I just went with the simple approach of the JTextField, but with a little checkbox that can remove the exact nature of the search (to make the application somewhat usable

However, I have known people to pass using both JTextField and JComboBox so I guess it's what you can live with.

Cheers /Dave
Yevgeniy Treyvus
Ranch Hand

Joined: Mar 09, 2005
Posts: 48
I would go with the JTextField. By the way, what do you mean by "bad data"?
If the user enters some jibberish (e.g. "&^&%^&aaevadf^%^%"), well just search for that and if there's nothing in the database that matches that just display a message (e.g. "Nothing found.").

Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Hello Jeroen, Cleverson, David and Yevgeniy ,
thanks a lot for your comments!

Cleverson, It's a gread idea, but SUN will not grade my application with additonal points if i implement both. But I like your idea! Thanks again.

Dave, I read a lot of topics where i found that some ppl use ComboBox and TextField. Therefor I ask this question.
But I think also that both are correct.

Yevgeniy, I just make one example. And this example was stuppid
With this i meant for example that the user will tipp the names with aphostrophe or special characters or another encoding,
that cann cause the problem if this special case will not be handled in code.
For example if the user enters some data with the special character and the client will sent this to server-side in xml-form (Don't worry I will not implement XML-staff, it's just example .
And the Server uses one parser to receive the information from xml.
And if the parser will found some special character it will throw some exception.
I agree. Here's the link: http://aspose.com/file-tools
subject: Search GUI: using JTextField vs. JComboBox
Similar Threads
My thoughts about the search dialog implementation
Database constant visibility
JComboBox versus JTextField in search pane
NX: Need help for GUI design
how to search in a JComboBox