首页 文章

Codename One Drag&Drop黑色对话框背景

提问于
浏览
1

我正在开发一个使用拖放操作的应用程序 . 拖放部分包括四个容器作为放置目标和两个可拖动标签 .

该应用程序在模拟器中按预期工作,但是当我将其安装在我的Android手机上时,一旦可拖动的组件(标签)被释放,对话框的背景(否则为白色)会立即变为黑色(然后返回到原来的浅色) .

在主题构建器中,我将对话框的背景设置为几乎白色(未选中,选中,按下,禁用),但这并未显示任何效果 .

是否有任何转变可以保持背景颜色稳定?任何帮助,将不胜感激 .

以下是相关的代码摘录:

Dialog dialog_W1 = new Dialog();
        dialog_W1.setScrollableY(true);
        dialog_W1.setLayout(new BoxLayout(2));
        dialog_W1.setScrollableY(true);
        dialog_W1.setTitle("Acerte o bichinho");              

        Image img_Cat = Image.createImage("/cat.png");
        ScaleImageLabel label_Scaled_Image = new ScaleImageLabel(img_Cat);
        label_Scaled_Image.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);        
        label_Scaled_Image.setUIID("NewLabel");        

        Label label_1 = new Label("ga");
        Label label_2 = new Label("to");

        label_1.setUIID("LabelWord");
        label_2.setUIID("LabelWord");

        label_1.setDraggable(true);
        label_2.setDraggable(true);

        Container c_1 = new Container();
        Container c_2 = new Container();
        Container c_3 = new Container();
        Container c_4 = new Container();

        c_1.setDropTarget(true);
        c_2.setDropTarget(true);
        c_3.setDropTarget(true);
        c_4.setDropTarget(true);

        c_1.setLayout(new BoxLayout(2));
        c_2.setLayout(new BoxLayout(2));
        c_3.setLayout(new BoxLayout(2));
        c_4.setLayout(new BoxLayout(2));

        c_1.setUIID("Container_1");
        c_2.setUIID("Container_1");
        c_3.setUIID("Container_2");
        c_4.setUIID("Container_2");

        c_3.add(label_2);
        c_4.add(label_1);

        GridLayout gl = new GridLayout(2,2);       
        Container container_0 = new Container(gl);    
        container_0.add(c_1);
        container_0.add(c_2);
        container_0.add(c_3);
        container_0.add(c_4);                  

        ArrayList <Container> list_Containers = new ArrayList<>(); 
        list_Containers.add(c_1);
        list_Containers.add(c_2);
        list_Containers.add(c_3);
        list_Containers.add(c_4);

        ArrayList <Label> list_Labels = new ArrayList<>();
        list_Labels.add(label_1);
        list_Labels.add(label_2);

        for (Label label : list_Labels) {
            label.addDragOverListener(new ActionListener() {                
                @Override
                public void actionPerformed(ActionEvent e) {                
                    for (Container c : list_Containers) {
                        int int_C = c.getComponentCount();
                        if (int_C == 1) {
                            c.setDropTarget(false);
                        } else if (int_C == 0) {
                            c.setDropTarget(true);
                        }
                    }
                }
            });  
        }

1 回答

  • 1

    我建议将Dialog显示为无模式对话框而不是使用 show 方法使用 showModless() 或类似 .

    由于模态对话框中固有的EDT嵌套,这种奇怪的事情可能会发生,通常我们不建议使用对话框而不是简单的通知 . 当我们使用拖放式对话框时,我们使用 InteractionDialog .

相关问题