如何在GXT中以编程方式设置BorderLayout的分割位置?
我使用 Ext-GWT 在小部件上设置了边框布局。有没有办法可以自动设置“分割”位置?原因是,如果用户调整页面上控件的大小(不一定是拆分小部件所在控件的父控件),我想将拆分值设置为某个百分比值(例如 30%)。这怎么能做到呢?
这是现有的代码:
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);
}
}
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 being, 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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是相当棘手的,
您需要访问非中心布局数据和边框布局小部件。
(中心是通过剩余空间计算的)。
然后使它们可用于 setSplitPositionTo 方法。
在我的例子中,我让他们成为班级成员。
最后我的方法如下所示,并且调用类似 myBorderLayoutInstance.setPlitPositionTo(0.4f);
使用您提供的示例和此修正案就像魅力一样。
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.