Reputation: 12185
I need to make a text box which autocompletes what the user is typing. I want something like a JComboBox that can update whenever the user types a new character based off of a set of possibilities. I want to do this by creating my own custom component by either extending JPanel or JComponent. What I am unsure about is how do I make a frame which can float over all other content. Like when you hit the drop down for a JComboBox how can I put a list of possibilities which floats above the background and underneath the text box?
Upvotes: 0
Views: 223
Reputation: 7
Try using jide components, they are built on swing and provide more advance gui features than swing.
Upvotes: 0
Reputation: 86
You need import SwingX (last version) on your project:
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
AutoCompleteDecorator this class contains only static utility methods that can be used to set up automatic completion for some Swing components.
Pass your JComboBox to the static method:
jComboBox1 = new javax.swing.JComboBox();
jComboBox1.setEditable(true);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "alejandro", "berenice", "juan", "ana", "bartolo", "diana", "cesar" }));
jComboBox1.setName("jComboBox1");
AutoCompleteDecorator.decorate(this.jComboBox1);
Upvotes: 1