SimplePanel只能包含一个子窗口小部件

时间:2016-06-21 14:33:43

标签: gwt panel children

当我运行以下代码并按下按钮"推送",不止一次,我得到浏览器错误" simplePanel只能包含一个子窗口小部件"。我该如何解决这个问题?先感谢您!乔吉

public class Projekt implements EntryPoint {

    private RootPanel rootPanel;

    public void onModuleLoad() {

        rootPanel = RootPanel.get("gwtContainer");
        rootPanel.setSize("1902", "868");

         final AbsolutePanel boundaryPanel = new AbsolutePanel();
         boundaryPanel.setStyleName("frame1");
         boundaryPanel.setSize("1455px", "600px");       

         final Diagram diagram = new Diagram(boundaryPanel);

         RootPanel.get().add(boundaryPanel, 446, 242);


         final Connector con = new Connector(100, 300, 300, 500);

         Button la = new Button("Push");
         la.setSize("200", "200");
         RootPanel.get().add(la);

         Button la2 = new Button("Push2");
         la2.setSize("200", "200");
         RootPanel.get().add(la2);

         final Image img = new Image("images/concrete.svg");
         img.setSize("200", "200");


         final Shape shapei = new Shape(img);


         Image img2 = new Image("images/variable.svg");
         img2.setSize("200", "200");
         boundaryPanel.add(img2, 200,200);

         final Shape shapei2 = new Shape(img2);
         shapei2.showOnDiagram(diagram);

         la.addClickHandler(new ClickHandler(){

            @Override
            public void onClick(ClickEvent event) {
                 boundaryPanel.add(img, 100,100);
                 shapei.showOnDiagram(diagram);
            }

         });
         la2.addClickHandler(new ClickHandler(){

                @Override
                public void onClick(ClickEvent event) {

                     con.showOnDiagram(diagram);
                }

             });


         diagram.addDiagramListener(new DiagramListenerAdapter() {

              @Override
              public void onElementConnect(ElementConnectEvent event) {
                if (con.startEndPoint.isGluedToConnectionPoint()) {
                    Widget connected = con.startEndPoint.gluedConnectionPoint.parentWidget;
                    if(connected.equals(shapei.connectedWidget)){
                  Image logo = new Image("images/xor.svg");
                  logo.setSize("100", "100");
                  boundaryPanel.add(logo);
                }
                    else if(connected.equals(shapei2.connectedWidget)){
                         Image logo2 = new Image("images/and.svg");
                      logo2.setSize("100", "100");
                      boundaryPanel.add(logo2);
                    };
              }}
            });

}}

3 个答案:

答案 0 :(得分:0)

我认为你的图表扩展了GWT的 SimplePanel  类? SimplePanel只能包含一个小部件,请看这里:

http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/SimplePanel.html

您可以扩展其他类,或者在尝试添加新窗口之前调用 remove(Widget w)方法删除现有窗口小部件。

答案 1 :(得分:0)

RootPanel.get()是一个SimplePanel。您尝试向其中添加多个子项,从而导致此错误。

相反,您应该将HTMLPanel添加到RootPanel,然后将所有子项添加到此HTMLPanel。

答案 2 :(得分:0)

我的初始化可能有问题吗?当我在clickevent中执行此操作时不会发生错误。但后来我无法使用我的diagramlistener ......