N
N
NoMoneyException2016-12-07 20:42:46
Java
NoMoneyException, 2016-12-07 20:42:46

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.


Added 2 JComboxes:
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);


I'm going to organize my search like this:
int iter = ((DefaultComboBoxModel) jComboBox1.getModel()).getIndexOf(toSearch);

        if (iter >= 0) {
            System.out.println("Founded: " + toSearch + ". Index: " + iter);
            jComboBox1.setSelectedIndex(iter);
        }


It remains to somehow expand these 2 lists and highlight the found lines. How to do it? Or maybe I didn't complete the task? But again, there are questions. The task states that there can be several found rows, and so I get only the index of one of them. You can pervert, write down the list without a line, then search there again, etc. But MB is there something simpler?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question