JavaFX最小化和通过动画最大化未装饰的舞台 [英] JavaFX Minimizing & Maximing undecorated stage with animations

查看:134
本文介绍了JavaFX最小化和通过动画最大化未装饰的舞台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个问题上使用了可接受的答案: JavaFX最小化未修饰的阶段以最小化我的应用正常.

I am using the accepted answer in this question: JavaFX Minimizing Undecorated Stage to minimize my app properly.

但是,不幸的是,默认Windows最小化了&最大化动画完全不显示(窗口只是显示和消失).

However, unfortunately the default Windows minimize & maximize animations are not shown at all (the window just appears and disappears).

我知道有可能使动画显示在未修饰的窗口中,因为我有一个具有这种行为的应用程序(PotPlayer).

I know it is possible to make the animations display with undecorated windows, since I have one application that has this behavior (PotPlayer).

如何使动画与JNA一起显示?

How could I make the animations appear with JNA?

编辑:这是一个有效的Kotlin代码段,用于适当地最小化JavaFX窗口,并增加了赏金.

Here's a working Kotlin code piece to minimize a JavaFX window properly, also added bounty.

fun makeMinimizable(stage: Stage) {
         val user32 = User32.INSTANCE
         val hWnd = user32.FindWindow(null, stage.title)
         val oldStyle = user32.GetWindowLong(hWnd, WinUser.GWL_STYLE)
         val newStyle = oldStyle or 0x00020000 // WS_MINIMIZEBOX
         user32.SetWindowLong(hWnd, WinUser.GWL_STYLE, newStyle)
    }

推荐答案

在对Windows动画进行进一步研究后,似乎可以一起破解某个解决方案.似乎更多的是操作系统问题,而不仅仅是JavaFX.

Upon further research on the Windows animations, it looks like a solution could be hacked together. It seems to be more of an OS issue and not just JavaFX.

通过在start()中进行修改,我能够使初始窗口保持未修饰的状态,同时将其最小化并使用动画:

I was able to get the initial window to stay undecorated while minimizing and with the animation by modifying this in start():

    int newStyle = oldStyle | 0x00020000 | 0x00C00000;

但是,在最小化并重新打开它之后,Windows边框似乎很奇怪.

But, after minimizing and reopening, the Windows border appears oddly enough.

然后,我尝试在图标化时使用ChangeListener交换Windows样式.

Then, I tried to use a ChangeListener to swap Windows styles when iconifying.

stage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
            if (t1.booleanValue() == true) {
                int newStyle = oldStyle | 0x00020000 | 0x00C00000;
                user32.SetWindowLong(hwnd, GWL_STYLE, newStyle);
            } else if (t1.booleanValue() == false) {
                int newStyle = oldStyle | 0x00020000;
                user32.SetWindowLong(hwnd, GWL_STYLE, newStyle);
            }
        }
    });

这成功地使窗口最小化动画以始终如一地正常工作,同时使(可见)舞台无边界.

This successfully gets the windows un-minimize animation to work fine consistently, while leaving the (visible) stage borderless.

一旦我找到了重新申请的最佳方法,看起来我就可以使最小化动画起作用:

It looks like I can get minimization animations working once I find out the best way to re-apply:

    int newStyle = oldStyle | 0x00020000 | 0x00C00000;
    user32.SetWindowLong(hwnd, GWL_STYLE, newStyle);

正好在舞台被图标化之前,并且边框对用户不可见.一旦实现,它可能与下面第一个链接中的C#解决方案类似.基本上,以上ChangeListener的作用相反.

just before the stage is iconified, and the border isn't visible to the user. Once implemented, this might work similarly to the C# solution in the first link below. Basically, what the above ChangeListener does in reverse.

我认为我们需要在后台侦听另一个线程来完成此解决方案,等待图标化事件发生.我认为触发事件时应该是stage.isIconified()== false,然后我们在后台线程中执行必要的任务来设置上述代码.然后,(最小限度起作用的)changeListener会将其重置为无动画的非框架窗口,当取消最小化时,直到再次将其最小化为止.

I think we need another thread listening in the background to finish up this solution, waiting for the iconified event to happen. I think stage.isIconified() == false should be the case when the event is fired, and then we execute the necessary task in the background thread to set the above code. Then, the (...somewhat working) changeListener will reset it back to a non-framed Window without animations, when un-minimizing, until it is minimized again.

有一个小错误,第一个未缩小显示我的舞台底部被剪切并复制了一点,但在后续操作后消失了.我们可能需要尝试将第二个十六进制更改为触发动画的其他内容,并在ChangeListener之外和其他线程中设置所有内容.

There is a minor bug with the first un-minimize displaying the bottom portion of my stage clipped and duplicated a little bit, but it disappears after subsequent actions. We may need to try changing the second hexadecimal to something else that triggers animations, and setting everything outside of the ChangeListener and in another thread.

我计划很快在自己的fx程序中完成此操作.我仍然是一名学生,所以我对多线程和服务没有太多的经验,但是我对如何进行处理有一个很好的主意,这将需要花费几个小时的时间.

I plan to finish this up soon in my own fx program. I'm still a student so I'm not too experienced with multithreading and services but I have a good idea on how to go about it, it will just take a few hours of hacking away.

如果您有任何进展,请告诉我!这是一个很好的起点.到目前为止,还没有人用Java解决这个问题.我正在阅读有关Steam等无边界程序已完成此操作的一些讨论,但我认为没有人能完全弄清楚他们是如何完成的,我怀疑这是通过下面的C#hack实现的.但是,对于我们的目的而言已经足够了.

Let me know if you make any progress in the meantime! This is a good starting point. Nobody has solved this issue in Java yet. I was reading up on some discussions that borderless programs like Steam have done this, but I don't think anyone could entirely figure out how they accomplished it, I doubt it was through the C# hack below. But, it's good enough for our purposes.

与解决无边界/未经修饰的动画有关的链接:

https://stackoverflow.com/a/31489766/7234125

^我们需要实现从C#到Java的答案,选项#1

https://exceptionshub .com/borderless-window-using-areo-snap-shadow-minimize-animation-and-shake.html

http://pinvoke.net/default.aspx/Constants/Window %20styles.html

这篇关于JavaFX最小化和通过动画最大化未装饰的舞台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆