我有一个应用程序,它将几个Windows放在com.extjs.gxt.desktop.client.Desktop中。我需要附加一个监听器,它在调整每个窗口大小时记录它们的大小。我看到两个问题:
在调整窗口大小时触发Move事件时,在实际将新大小应用于窗口之前,它们似乎被触发,因此我无法直接从窗口请求新大小。
< / LI>我在Listener中收到的WindowEvent大小为0x0,与窗口的实际大小无关。
这里有什么我想念的吗?
这是我的附加代码:
protected void addWindowListeners( Window w,
String uid, WindowData windowData )
{
WindowChangeListener l = new WindowChangeListener( uid, windowData );
w.addWindowListener( l );
// Add this again since the default WindowListener doesn't support the Move event.
w.addListener( Events.Move, l );
}
听众类:
protected class WindowChangeListener
extends WindowListener
implements Listener<WindowEvent>
{
@Override
public void windowHide( WindowEvent we )
{
updateWindowData( we );
}
@Override
public void windowShow( WindowEvent we )
{
updateWindowData( we );
}
public void windowMove( WindowEvent we )
{
updateWindowData( we );
}
protected void updateWindowData( WindowEvent we )
{
// Here's the part that needs to get notified with the new size.
}
@Override
public void handleEvent( WindowEvent we )
{
if( we.getType() == Events.Move )
windowMove( we );
else
super.handleEvent( we );
}
}
感谢任何人的洞察力。我觉得我必须错过一些简单的东西。
答案 0 :(得分:1)
我实际上在Sencha论坛上获得了魔力:http://www.sencha.com/forum/showthread.php?121249-What-s-the-right-way-to-be-notified-when-a-Window-is-resized&p=561340&posted=1#post561340
原来我可以在Window上监听resize事件:
protected void addWindowListeners( Window w,
String uid, WindowData windowData )
{
w.addListener( Events.Resize, new Listener<WindowEvent>() {
@Override
public void handleEvent( WindowEvent we )
{
System.out.println( "Resize event: " + we );
System.out.println( " Size in event: " + we.getWidth() + "x" + we.getHeight() );
System.out.println( " Size of window: " + we.getWindow().getSize() );
}
});
}