A
A
artem2020-12-05 15:07:54
Java
artem, 2020-12-05 15:07:54

Roughly speaking, how to create a list of variables?

There are several CheckBox(1,2,3,4...) variables, I want to attach an event to each variable of the CheckBox type, when clicking on the variable will automatically mark the previous variables, for example, if I click on the second CheckBox, then the first one too is pressed, and if on 4, then all up to 4 and including the fourth are also marked.

Here's what I tried to implement, but the code doesn't work.

Map<String, CheckBox> chekList = new LinkedHashMap<>();

        chekList.put("one_chek", one_chek);
        chekList.put("two_chek", two_chek);
        chekList.put("three_chek", three_chek);
        chekList.put("four_chek", four_chek);
        chekList.put("five_chek", five_chek);
        chekList.put("six_chek", six_chek);
        chekList.put("seven_chek", seven_chek);

        for(int i = 0; i < chekList.size()-1; i++) {
            chekList.get(i+1).setOnAction(actionEvent -> {
                for(int i2 = 0; i2 < chekList.size(); i2++){
                    chekList.get(i2).setSelected(true);
                }
            });
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2020-12-05
@xez

Everything is as usual. With List, Set, Map...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question