我正在使用 Vaadin 7.1
我有 2 个布局:
| 标题 |
| 主要 |
和弹出窗口。
当我最大化窗口时,我希望它在“主”中打开,而不是在整个屏幕中打开。可能吗?
当我尝试直接执行此操作时,我得到:
java.lang.IllegalArgumentException:只能使用 UI.addWindow(Window window) 将窗口添加到 UI
问候,Oleksandr。
我正在使用 Vaadin 7.1
我有 2 个布局:
和弹出窗口。
当我最大化窗口时,我希望它在“主”中打开,而不是在整个屏幕中打开。可能吗?
当我尝试直接执行此操作时,我得到:
java.lang.IllegalArgumentException:只能使用 UI.addWindow(Window window) 将窗口添加到 UI
问候,Oleksandr。
我认为您需要一些 javascript 和自定义逻辑。
首先,您必须设置主布局 id:
mainLayout.setId("xyz");
这是扩展窗口:
public class MyWindow extends Window {
private static final long serialVersionUID = 1L;
private int top;
private int left;
private int bottom;
private int right;
public MyWindow() {
setResizable(false);
setData(WindowMode.NORMAL);
String sourceURL = "javascript:com.xyz.foo.myfunc(" +
"document.getElementById('xyz').getBoundingClientRect().top," +
"document.getElementById('xyz').getBoundingClientRect().left," +
"document.getElementById('xyz').getBoundingClientRect().bottom," +
"document.getElementById('xyz').getBoundingClientRect().right)";
final Link link = new Link("maximization", new ExternalResource(sourceURL));
// set link icon if needed
JavaScript.getCurrent().addFunction("com.xyz.foo.myfunc", new JavaScriptFunction() {
private static final long serialVersionUID = 1L;
@Override
public void call(JSONArray arg) throws JSONException {
if (MyWindow.this.getData() == WindowMode.NORMAL) {
saveCurrentPos();
setPos(arg.getInt(0), arg.getInt(1), arg.getInt(2), arg.getInt(3));
link.setCaption("normalization"); // or set icon
MyWindow.this.setData(WindowMode.MAXIMIZED);
} else {
setPos(top, left, bottom, right);
link.setCaption("maximization"); // or set icon
MyWindow.this.setData(WindowMode.NORMAL);
}
}
});
VerticalLayout vLayout = new VerticalLayout(link);
vLayout.setComponentAlignment(link, Alignment.TOP_RIGHT);
setContent(vLayout);
// demo settings
setWidth("200px");
setHeight("150px");
center();
}
private void saveCurrentPos() {
left = getPositionX();
top = getPositionY();
right = left + (int) getWidth();
bottom = top + (int) getHeight();
}
private void setPos(int top, int left, int bottom, int right) {
setPositionX(left);
setPositionY(top);
setWidth(right - left, Unit.PIXELS);
setHeight(bottom - top, Unit.PIXELS);
}
}
我建议您使用标题和关闭按钮编写自己的标题。