2015-02-06 91 views
0

我正在開發一個簡單的GXT小部件 - 它是一個TreePanel,其中使用setTopComponent添加了一個ToolBar。 問題是隻要樹足夠大以便可以滾動,滾動條就不會僅滾動樹,而是滾動ToolBar。GXT ToolBar滾動

enter image description here

應該是什麼變化,使該工具欄仍然在頁面的頂部,只有樹滾動。

public class TreePanelExample extends LayoutContainer { 

    @Override 
    protected void onRender(Element parent, int index) { 
     super.onRender(parent, index); 

     Folder model = getTreeModel(); 

     TreeStore<ModelData> store = new TreeStore<ModelData>(); 
     store.add(model.getChildren(), true); 

     final TreePanel<ModelData> tree = new TreePanel<ModelData>(store); 
     tree.setDisplayProperty("name"); 
     tree.setAutoLoad(true); 

     ToolBar toolBar = new ToolBar(); 
     toolBar.setBorders(true); 

     toolBar.add(new Button("Dummy button", new SelectionListener<ButtonEvent>() { 
      public void componentSelected(ButtonEvent ce) { 
       Info.display("Dummy button", "I'm so dumb!"); 
      } 
     })); 

     ContentPanel panel = new ContentPanel(); 
     panel.setHeaderVisible(false); 
     panel.setCollapsible(false); 
     panel.setFrame(false); 
     panel.setAutoWidth(true); 
     panel.setAutoHeight(true); 
     // setting fixed size doesn't make any difference 
     // panel.setHeight(100); 
     panel.setTopComponent(toolBar); 
     panel.add(tree); 

     add(panel); 
    } 
+0

它的版本您使用GXT? – 2015-02-09 17:42:01

+0

我使用版本2.3.0 – gnom1gnom 2015-02-11 18:11:19

回答

0

的問題是,

TreePanelExample extends LayoutContainer 

而相反,它應該擴展口。

此外,我不應該使用

panel.setAutoWidth(true); 
panel.setAutoHeight(true); 

加上它需要添加使用

new BorderLayoutData(LayoutRegion.CENTER); 

下面是完整的解決方案的主面板:

public class TreePanelExample extends Viewport { 

public TreePanelExample() { 
    super(); 
    setLayout(new BorderLayout()); 

    Folder model = getTreeModel(); 

    TreeStore<ModelData> store = new TreeStore<ModelData>(); 
    store.add(model.getChildren(), true); 

    final TreePanel<ModelData> treePanel = new TreePanel<ModelData>(store); 
    treePanel.setDisplayProperty("name"); 
    treePanel.setAutoLoad(true); 

    ToolBar toolBar = new ToolBar(); 
    toolBar.setBorders(true); 

    toolBar.add(new Button("Dummy button", new SelectionListener<ButtonEvent>() { 
     public void componentSelected(ButtonEvent ce) { 
      Info.display("Dummy button", "I'm so dumb!"); 
     } 
    })); 

    ContentPanel panel = new ContentPanel(); 
    panel.setBodyBorder(false); 
    panel.setHeaderVisible(false); 

    panel.setTopComponent(toolBar); 
    panel.setLayout(new FitLayout()); 
    panel.add(treePanel); 

    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER); 
    centerData.setMargins(new Margins(5, 5, 5, 5)); 
    centerData.setCollapsible(true); 
    panel.syncSize(); 

    add(panel, centerData); 
}