0

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?

chasep255
  • 11,745
  • 8
  • 58
  • 115
  • You might find some help from [this question](http://stackoverflow.com/questions/14186955/create-a-autocompleting-textbox-in-java-with-a-dropdown-list). – MikeM Jul 07 '14 at 20:54
  • You have at last three choices, either JPopupMenu or JWindow or an undecorated JFrame/JDialog – MadProgrammer Jul 07 '14 at 20:59

2 Answers2

1

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);
  • That works but the only problem is I want to user to also be able to type things outside the range of possibilities. – chasep255 Jul 08 '14 at 14:39
0

Try using jide components, they are built on swing and provide more advance gui features than swing.

Vivek Pathak
  • 7
  • 1
  • 5