2010-03-23 76 views
1

簡單的問題.... 如果我在左側StackLayoutPanel,我想點擊它有一個動態加載 小部件在我DockLayoutPanel右邊......類似GWT例子 http://gwt.google.com/samples/Mail/Mail.html ..點擊郵箱 下的任何東西都會在右側觸發不同的小部件...UiBinder的動態DockPanel中

+0

你看過Mail示例的源代碼嗎? http://code.google.com/p/google-web-toolkit/source/browse/#svn/trunk/samples/mail/src/com/google/gwt/sample/mail - 這是非常舊的代碼,但發生了什麼事情的基礎知識應該在那裏。 – 2010-03-23 12:47:09

+0

傑森,我有......但它沒有回答這個問題,關於StackLayoutPanel項目動態地在Dock Panel佈局區域之一中的小部件...所有煙霧和鏡像在這方面 – murray 2010-03-24 04:03:17

+0

真的你問的是如何基於點擊事件將另一個小部件替換爲另一個小部件,對嗎? – 2010-05-06 15:06:43

回答

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); 
    } 
}