I have to make what is called "Hypertext Searching" in my application. Basically, you start typing in a field, and just like Google for each letter you type in, the relevant search matches changes. The only difference is, that I will fill a table with information, and every time the user types a letter in the box, the table will change content based on what you start typing.
An example would be that if you wanted to look for a Harry Potter book, you start typing Harry.
For each letter you type, the table changes, nailing down letter for letter what book it is you are looking for.
My question is: Which way would be the best or most appropriate way of doing it efficiently? I am going to have an array list with objects in, that I can access and show on the table.
This functionality is called autocompletion.
There is plenty of solution if you search on google "javascript autocompletion".
Personnally I use jquery ui which has a component for that http://jqueryui.com/demos/autocomplete/
EDIT: My bad, the question is about java, not javascript
Have you tried
SuggestBox using GWT and
Facebook Style Autocomplete?
Related
I have on my server a parser and a searcher for lucene query that search on xml and i have an android application that use this service.
Until now this android application has used the searcher in a simple way. Writing something on a text widget and clicking on a button it's like search:
title: something
It's found all the files which have on title "something".
But the service permit to me to search things like:
mediatype:audio AND mtime:[45dayago TO now] AND metadata_count:[04 TO 99]
More info on lucene query are here.
For user it's realy difficult know what terms are valid or how to describe advanced query but it's realy important to search on an archive. I would try to make an easy and valid lucene query to help the user to use that advanced search experience.
Any ideas would be appreciated.
If it were me, I'd start by constructing a view that has an arbitrary number of TextEdit boxes (the user can select how many, possibly via a spinner or a "add more" button). Then have a selector whether these terms are to be "ANDed" or "ORed" together.
Once you have that working, enhance each entry to be more than just a TextEdit, but to have options for entering numbers (via spinners?), ranges (via slider?) or dates/times (via a calendar picker?)?
The key here is to take an iterative approach. Implement one additional capability, and make sure it works, before moving on to the next one.
I was working on creating a weather application in Java using Weather Underground and I found that it does have data for some cities.
Initially, I was planning on using GeopIP to get the user's location automatically but since the support for cities is limited I decided to let the user choose the city every time the program starts.
I want the user to be able to choose a city from one that is supported by Weather Underground. The user will enter the name and as he/she enters the name, the possible locations will be displayed in a way similar to the one shown in the picture.
My question is:
How do I implement this search feature ?
My initial guess was to create a Vector containing all the names of the cities and then use brute force to find the match and display in a JPopup or a JWindow containing a JList but I guess there has to be a better method
Rephrase:
What I do not understand is WHAT INFO do I keep in the data structure I must use ? Should I manually create a list of cities that Weather Underground supports or is there another way to do it ?
Take a look at the Trie data structure (also known as digital tree or prefix tree). Autocompletion is one of the most common examples of it's usefulness.
The following article has a nice an very approachable explanation:
Roll your own autocomplete solution using Tries.
if you google autosuggestcombobox you will get some interesting results:
This one is written in JavaFX - I have used and extended it myself already. It is quite useful. What you get "for free" with JavaFX: a context menu with right-mouse click which is auto-generated containing some of the usual "stuff", like cut, copy & paste and even undo! So, I can recommend that solution. To get into JavaFX isn't so hard - and I think it is much easier to learn than Swing - and looks so much cooler! However this implementation has some drawbacks - especially when the layout is not left-aligned, because it is simply a text field on top of a combobox.
OK - but if you want to stick to Swing - you could probably use this one. I haven't used that myself, but the code looks quite straightforward and pretty clean - cleaner than the implementation for JavaFX I must admit (but that had some nice features). So - maybe you try - and extend it? It is built simply on JComboBox.
I'm building on top of an existing UI which is in Swing. I need to add a search module wherein the user can enter search terms which should be auto-complete'd.
I'm considering building a UI very similar to Stackoverflow's 'tagging a question' feature. So in my use case each 'tag' would be a search term.
I'm completely new to Swing or UIs in general and have very little clue on how to start.
Any advice/pointers on how and where to start would be of great value to me.
there are two ways
exactly same way is implemeting Filtering for JTable (there started after 2nd or 3rd chars typed)
of use AutoComplete JComboBox / JTextField
You should use and ArrayList where every time someone types a keyword into the search box and clicks find, the program goes in a while loop and searches all topics with that particular tag. and hence can be displayed later as a list with found solutions.
I have a textfield and if I want to write something to the field, it will show me the list of possible options regarding to that letter and I think this is called an auto complete.
Could someone give me an idea or a sample on how to do it?
Thanks..
Take a combo box and listen to all changes in the textfield. On every event, read the actual content and query your source list for possible matches. Then use the result to populate the associated list.
You may want to start autocompletion once the user has entered two or three letters, otherwise the list may get too long..
look here is AutoCompleteComboBox / JFextField, and there are two classes one for JComboBox, second for JTextField, notice auto-complete functionality requires both classes for that
I feeling generous as you really should google ...
As the user types, you'd need to query your DB with a like '<userInput>%' and return the results into a pulldown. You probably want to wait for a pause in the user's typing so as not to hammer your DB.
In the absence of a database, a data structure that would work well for this is called a Trie as you can traverse it past the initial input and present all the subsequent words.
I'm wandering myself what component is the best for displaying fast search results in swing. I want to create something like this, make a text field where user can enter some text, during his entering I'll improve in back end fast search on database, and I want to show data bellow the text box, and he will be able to browse the results and on pres enter result will be displayed in table. So my question is is there any component which already have this logic for displaying?
Or is it's not, what is the best way to implement that.
This search will be something what ajax gives me on web, same logic same look and feel, if it's possible on desktop application.
Are you looking for something like an AutoComplete component for Java Swing?
SwingX has such a component. See here for the JavaDoc. It has a lot of utility methods to do various things, i.e. auto-completing a text box from the contents of a JList.
I strongly, strongly recommend that you take a look at Glazed Lists - this is one of the finer open source Java libraries out there, and it makes the bulk of what you are asking about super easy.
You will have to first attach a listener to the JTextFields Document to be notified whenever the user types in the field (or changes it).
From there, you can fire off any server-side code you need. The results of that can be used to update a listbox.
A few things to keep in mind:
The code to do the search against the backend must be in another thread
The code that updates the list box should update the list box's model
You will need to manage all your backend search results so that you only update the listbox with the most recent result (e.g. user types 'A', backenf searches for that. Meanwhile, user has typed 'C', kicking off a backend search for 'AC'. You need to ensure the results from the 'A' search dont' make it to the listbox if the 'AC' search results are available).
Use Hibernate Search.
The SwingHack (http://oreilly.com/catalog/9780596009076/) book has an example of this.
In the interest of killing two birds with one stone: have a separate indexing thread. This will:
Improve the speed of searches whenever they are executed.
Improve the responsiveness of the UI since indexing is happening in a separate thread.
Of course, exactly how you perform the indexing will vary widely depending on your particular application. Here is a good place to start researching: Search Indexing. And please, ignore the reference to Web 3.0 [sic].
It is possible of course. It is simple too. For drop down list of terms just use popup menu. This is simple. The background processing of entered text is simple too. Enjoy!