I'm interested in providing an autocompletion box in a JFrame. The triggering mechanism will be based on mnemonics (I think), but I'm not really sure what to use for the "autocompletion box" (I would like results to be filtered as the user presses keys).
How would you implement this? Some sort of JFrame, or a JPopupMenu?
I would like to know how this is implemented, so please don't post links to available [J]Components.
Using the Code add("example"); keywords. add("autocomplete"); keywords. add("stackabuse"); keywords. add("java"); Autocomplete autoComplete = new Autocomplete(mainTextField, keywords); mainTextField.
Swing in java is part of Java foundation class which is lightweight and platform independent. It is used for creating window based applications. It includes components like button, scroll bar, text field etc. Putting together all these components makes a graphical user interface.
The pack() method is defined in Window class in Java and it sizes the frame so that all its contents are at or above their preferred sizes. An alternative to the pack() method is to establish a frame size explicitly by calling the setSize() or setBounds() methods.
You might want to try the free AutoComplete component over at SwingLabs.
http://swinglabs.org
Edit: This site seems to have moved http://java.net/projects/swinglabs
There is an example how to implement this code at:
http://download.java.net/javadesktop/swinglabs/releases/0.8/docs/api/org/jdesktop/swingx/autocomplete/package-summary.html
There is an example for auto-completion for text area at
Sun's tutorials "Using Swing Components".
It is done in the style of word processors (no pop ups, but the
suggested text is typed ahead of the cursor).
Just scroll down to "Another Example: TextAreaDemo"
ant hit the Launch button!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With