1

简单的问题....如果我在左侧有一个 StackLayoutPanel,我想单击它在右侧的 DockLayoutPanel 中有一个动态加载的小部件...类似于 GWt 示例 http://gwt.google.com/samples/ Mail/Mail.html .. 单击邮箱下的任何内容都会触发右侧的不同小部件...

4

1 回答 1

1

我没有使用您正在使用的特定小部件,但这是一般的想法。

public class Index implements EntryPoint {

    public void onModuleLoad() {
        // the panel that holds the content widgets
        final SimplePanel mainPanel = new SimplePanel();
        // the panel that holds the links
        FlowPanel leftPanel = new FlowPanel();
        // the first content widget
        final Label oneContent = new Label("one content");
        // the second content widget
        final Label twoContent = new Label("two content");
        // the anchor to load the first content widget when clicked
        Anchor one = new Anchor("one menu");
        // add the click handler to do the content swap
        one.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                // remove any previous content
                mainPanel.clear();
                // add the first content widget
                mainPanel.add(oneContent);
            }
        });

        // the anchor to load the first content widget when clicked
        Anchor two = new Anchor("two menu");
        // add the click handler to do the content swap
        two.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                // remove any previous content
                mainPanel.clear();
                // add the second content widget
                mainPanel.add(twoContent);
            }
        });

        leftPanel.add(one);
        leftPanel.add(two);
        // add everything to the RootPanel
        RootPanel.get().add(leftPanel);
        RootPanel.get().add(mainPanel);
    }
}
于 2010-05-06T15:11:02.850 回答