ComponentSelector不能以正确的顺序返回Components

时间:2019-08-31 01:48:41

标签: codenameone

对于我的用例,至关重要的是,ComponentSelector.$("#...", myCnt)返回选择的组件,使其返回顺序与给定容器中显示的顺序相同,假设我使用的是{{1 }},并且我在调用BoxLayout.y()之前添加和删除了组件。

当前ComponentSelector以随机顺序返回组件。

示例:

ComponentSelector.$("#...", myCnt)

输出:

Form hi = new Form("Hi World", BoxLayout.y());
        Label label1 = new Label("cmp 1");
        label1.setName("toBeSaved");
        Label label2 = new Label("cmp 2");
        label2.setName("toBeSaved");
        Label label3 = new Label("cmp 3");
        label3.setName("toBeSaved");
        Label label4 = new Label("cmp 4");
        label4.setName("toBeSaved");
        Label label5 = new Label("cmp 5");
        label5.setName("toBeSaved");
        Label label6 = new Label("cmp 6");
        label6.setName("toBeSaved");
        Label label7 = new Label("cmp 7");
        label7.setName("toBeSaved");
        Label label8 = new Label("cmp 8");
        label8.setName("toBeSaved");
        Label label9 = new Label("cmp 9");
        label9.setName("toBeSaved");
        Label label10 = new Label("cmp 10");
        label10.setName("toBeSaved");
        hi.addAll(label1, label2, label3, label4, label5, label6, label7, label8, label9, label10);
        hi.show();

        for (Component cmp : ComponentSelector.$("#toBeSaved", hi.getContentPane()).asList()) {
            if (cmp instanceof Label) {
                Log.p(((Label) cmp).getText());
            }
        }

1 个答案:

答案 0 :(得分:1)

这是由于该类使用HashSet来防止重复而引起的。我用LinkedHashSet代替了它,有望解决该问题:https://github.com/codenameone/CodenameOne/commit/2ef6a77e4f8ac3475a8c05541b8ac829099ac9a9