【问题标题】:Vaadin add/remove components with buttonclickVaadin 使用 buttonclick 添加/删除组件
【发布时间】:2017-11-15 00:31:16
【问题描述】:

如何检查组件是否已经在布局中?

我有一个 4x4 网格布局 带有一些按钮

一个按钮是显示一个数据网格 一个显示输入字段

我想做的是

MenuBar.Command tablecommand = new MenuBar.Command() {
        public void menuSelected(MenuItem selectedItem) {
            output.setValue("clean components");
            layout2.removeComponent(name);
            layout2.removeComponent(name2);
            layout2.removeComponent(button);
            layout2.removeComponent(cp);

            //layout2.removeComponent(grid);
            //if layout2 !contains grid

            layout2.addComponent(grid,1,2);

        }
    };

没有检查我得到一个异常

  java.lang.IllegalArgumentException: Component is already in the container
    at com.vaadin.ui.GridLayout.addComponent

当我第二次点击 showgrid 按钮时

我唯一能找到的是“.equals(obj)”

【问题讨论】:

    标签: dynamic components vaadin


    【解决方案1】:

    您可以查看组件是否有父组件。 如果是,那么它已经在某个地方。

    https://vaadin.com/api/com/vaadin/ui/Component.html#getParent--

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2016-03-09
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      相关资源
      最近更新 更多