0

我正在创建 ContentPanel 并将其隐藏:

final ContentPanel infoPanel = new ContentPanel(); 
final TabPanel infoTabPanel = new TabPanel();
...
//Adding TabItems with some forms
infoPanel.add(infoTabPanel);
infoPanel.hide();
add(infoPanel);

然后在一些事件监听器中,我尝试显示这个隐藏的面板:

infoPanel.show();
infoPanel.layout();

但是这个面板没有任何数据显示。只有当我点击标签数据时才会出现。

那么如何正确隐藏/显示这个面板呢?

编辑:

我正在使用 GXT 2.2.4。
我正在使用包含 FormPanel 并隐藏 ContentPanel 的 TabPanel 创建 ContentPanel。

然后在事件侦听器中,我尝试显示这个隐藏的面板,但它没有表单显示。只有当我点击标签表单时才会出现。

这是代码:

protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);
    final ContentPanel infoPanel = new ContentPanel();
    infoPanel.setAutoHeight(true);
    final TabPanel infoTabPanel = new TabPanel();
    infoTabPanel.setAutoHeight(true);

    final FormPanel testForm = new FormPanel();

    FieldSet fieldSet = new FieldSet();
    fieldSet.setHeading("Information");

    FormLayout fLayout = new FormLayout();
    fieldSet.setLayout(fLayout);

    LabelField field1 = new LabelField();
    LabelField field2 = new LabelField();

    field1.setFieldLabel("Field1:");
    field1.setName("field1");

    fieldSet.add(field1);

    field2.setFieldLabel("Field2:");
    field2.setName("field2");
    fieldSet.add(field2);
    testForm.add(fieldSet);

    TabItem formTab = new TabItem("Form Tab");
    formTab.add(testForm);
    infoTabPanel.add(formTab);

    TabItem longText = new TabItem("Long Text");
    longText.addStyleName("pad-text");
    longText.addText("Long Text" + "<br>" + "Long TextLong Text");
    infoTabPanel.add(longText);

    infoPanel.add(infoTabPanel);
    infoPanel.hide();

    Button buttonShow = new Button("show");
    buttonShow.addSelectionListener(new SelectionListener<ButtonEvent>() {
        @Override
        public void componentSelected(ButtonEvent ce) {
            infoPanel.show();
        }
    });

    Button buttonHide = new Button("hide");
    buttonHide.addSelectionListener(new SelectionListener<ButtonEvent>() {
        @Override
        public void componentSelected(ButtonEvent ce) {
            infoPanel.hide();
        }
    });

    add(infoPanel);
    add(buttonShow);
    add(buttonHide);

}
4

2 回答 2

0

你有哪个 GXT 版本?我无法在 GXT 3.x 上重现您的问题。我写了一个小示例代码,它完全符合您的要求。

public void onModuleLoad() {

    final ContentPanel infoPanel = new ContentPanel();
    final TabPanel infoTabPanel = new TabPanel();

    infoTabPanel.add(new TextButton("moo"), "moo");
    infoTabPanel.add(new TextButton("boo"), "boo");
    infoPanel.add(infoTabPanel);
    infoPanel.hide();

    VerticalLayoutContainer vlc = new VerticalLayoutContainer();
    vlc.setPixelSize(300, 250);

    TextButton buttonShow = new TextButton("show");
    buttonShow.addSelectHandler(new SelectHandler() {

        @Override
        public void onSelect(SelectEvent event) {
            infoPanel.show();
        }
    });

    TextButton buttonHide = new TextButton("hide");
    buttonHide.addSelectHandler(new SelectHandler() {

        @Override
        public void onSelect(SelectEvent event) {
            infoPanel.hide();
        }
    });

    vlc.add(infoPanel, new VerticalLayoutData(1, 1));
    vlc.add(buttonShow);
    vlc.add(buttonHide);
    RootPanel.get().add(vlc);
}
于 2013-01-30T16:33:13.833 回答
0

好的我明白了。

好的,我明白了,既然单击选项卡会显示它,为什么不以编程方式在侦听器中选择选项卡?

infoTabPanel.setSelection(formTab);

http://dev.sencha.com/deploy/gxt-2.2.5/docs/api/com/extjs/gxt/ui/client/widget/TabPanel.html#setSelection(com.extjs.gxt.ui.client.小部件.TabItem)

---------下面没有工作------------

所以试试infoPanel.repaint();

于 2013-01-31T11:01:58.523 回答