调整窗口大小时收到通知的正确方法是什么?

发布于 2024-10-11 11:38:16 字数 1473 浏览 3 评论 0原文

我有一个应用程序,将多个 Windows 放置在 com.extjs.gxt.desktop.client.Desktop 中。我需要附加一个侦听器,它在调整大小时记录每个窗口的大小。我看到两个问题:

  1. 虽然调整窗口大小时会触发移动事件,但它们似乎是在新大小实际应用于窗口之前触发的,因此我无法直接从窗​​口请求新大小。< /p>

  2. 无论窗口的实际大小如何,我在侦听器中收到的 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 );
    }
}

感谢任何人的见解。我觉得我必须错过一些简单的东西。

I have an application that places several Windows within a com.extjs.gxt.desktop.client.Desktop. I need to attach a listener which records the size of each window when it is resized. I'm seeing two issues:

  1. While Move Events are fired when the window is resized, they appear to be fired BEFORE the new size is actually applied to the window, so I cannot request the new size from the window directly.

  2. The WindowEvent I receive in my Listener contains a size of 0x0, regardless of the actual size of the window.

Is there something I'm missing here?

Here's my attach code:

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 );
}

And the listener class:

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 );
    }
}

Thanks for any insight anyone has. I feel like I've got to be missing something simple.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒眉千度 2024-10-18 11:38:16

事实上,我在 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 上的调整大小事件:

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() );
        }

    });
}

I actually was given the magic on the Sencha forums: 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

Turns out that I can listen for a resize event on Window:

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() );
        }

    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文