开发者

How to programmatically set the split position of BorderLayout in GXT?

I have a border layout set on a widget using Ext-GWT. Is there a way where I can set the 'split' position automatically? Reason bei开发者_运维知识库ng, if the user resizes a control on a page (not necessarily the parent of the one the split widget is in), I'd like to set the split value to a certain percentage value (like 30%). How can this be done?

Here's the existing code:

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.user.client.Element;

public class BorderLayoutExample extends LayoutContainer {  

  setSplitPositionTo(float percentage) {
  // TODO: How to do this?
  }

  protected void onRender(Element target, int index) {  
    super.onRender(target, index);  
    final BorderLayout layout = new BorderLayout();  
    setLayout(layout);  
    setStyleAttribute("padding", "10px");  

    ContentPanel west = new ContentPanel();  
    ContentPanel center = new ContentPanel();  

    //uncomment this section if you dont want to see headers
    /*
     * west.setHeaderVisible(false);
     * center.setHeaderVisible(false);
     */

    BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 150);  
    westData.setSplit(true);  
    westData.setCollapsible(true);  
    westData.setMargins(new Margins(0,5,0,0));  

    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
    centerData.setMargins(new Margins(0));  

    add(west, westData);  
    add(center, centerData);  
  }  
}  


This one was fairly tricky

You'll need to get access to a non center layoutdata and widget for the border layout. (As center is calculated via remaining space). Then make them available to the setSplitPositionTo method.

In my example I made them members on the class. In the end my method looks as follows and a call like myBorderLayoutInstance.setPlitPositionTo(0.4f); works like a charm using the example you provided and this amendment.

BorderLayoutData westData;
ContentPanel west;

void setSplitPositionTo(float percentage) {
  westData.setSize(percentage);
  Component c = west;
  Map<String, Object> state = c.getState();
  state.put("size", westData.getSize());
  c.saveState();
  layout(true);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜