1 package edu.jiangxin.apktoolbox.swing.extend.autocomplete;
2
3 import javax.swing.*;
4 import java.io.Serial;
5 import java.util.Vector;
6
7
8
9
10
11
12 public class AutoCompleteComboBox<E> extends JComboBox<E> {
13
14 @Serial
15 private static final long serialVersionUID = 1L;
16 private transient AutoCompleter<E> completer;
17
18 public AutoCompleteComboBox() {
19 super();
20 }
21
22
23 public void initialize() {
24 setUI(new ScrollBasicComboBoxUI());
25 setEditable(true);
26 completer = new AutoCompleter<>(this);
27 }
28
29 public void autoComplete(String str) {
30 this.completer.autoComplete(str);
31 }
32
33 public String getText() {
34 return ((JTextField) getEditor().getEditorComponent()).getText();
35 }
36
37 public void setText(String text) {
38 ((JTextField) getEditor().getEditorComponent()).setText(text);
39 }
40
41 public boolean containsItem(String itemString) {
42 for (int i = 0; i < this.getModel().getSize(); i++) {
43 String item = " " + this.getModel().getElementAt(i);
44 if (item.equals(itemString)) {
45 return true;
46 }
47 }
48 return false;
49 }
50 }
51