Answer the question
In order to leave comments, you need to log in
How to highlight items in JComboBox and a few other questions?
Hello. There is a task:
Develop an application that searches two
drop-down lists for a piece of text. Use a set of flags
to specify in which list the search will be performed.
The lines in which the search fragment will be found must be highlighted
(it is assumed that several lines may have the search fragment).
In addition, the application must provide management of the contents of the
lists - adding a new element, editing, deleting.
String[] list1 = {"Minsk", "New York", "Paris", "London"};
JComboBox<String> jComboBox1 = new JComboBox<>(list1);
String[] list2 = {"Brest", "New Minneapolis", "Twin Falls", "Santa Fe"};
JComboBox<String> jComboBox2 = new JComboBox<>(list2);
int iter = ((DefaultComboBoxModel) jComboBox1.getModel()).getIndexOf(toSearch);
if (iter >= 0) {
System.out.println("Founded: " + toSearch + ". Index: " + iter);
jComboBox1.setSelectedIndex(iter);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question