简体   繁体   English

从子窗口小部件调用面板的add方法

[英]Calling a panel's add method from a child widget

I have created a Composite widget comprising of a TextBox and a Button. 我创建了一个由TextBox和Button组成的Composite小部件。 What I am trying to implement here is that another instance of this widget be added to its parent vertical panel on entering text in the TextBox of widget. 我要在这里实现的是,在小部件的TextBox中输入文本时,将该小部件的另一个实例添加到其父垂直面板。 To achieve that I've tried following: 为此,我尝试了以下操作:

public void onKeyPress(KeyPressEvent event){
    if(event.getSource() == optionBox && optionCount>=2){
        getParent().add(new OptionWidget(optionCoutn+1));
    }
}

But I am getting an error:That "symbol: method add(Widget)" cannot be found in Widget class. 但是我遇到一个错误:在Widget类中找不到“符号:方法add(Widget)”。 From which it is obvious that add method from VerticalPanel class is not being called here. 很明显,这里没有调用VerticalPanel类的add方法。

I've added two instances of this widget to VerticalPanel using UiBinder template. 我已使用UiBinder模板将此小部件的两个实例添加到VerticalPanel。

What should I do to call VerticalPanel's add method ? 我应该怎么做才能调用VerticalPanel的add方法?

Convert the result of getParent to VerticalPanel getParent的结果转换为VerticalPanel

VerticalPanel ParentPanel=(VerticalPanel)getParent();
ParentPanel.add(new OptionWidget(optionCoutn+1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM