在 Java 11 中使用 Java AWT 获取 Compent 的 Winows 句柄以实现 OpenOffice 集成

问题描述

几年前,我编写了一个包含 OpenOffice Writer 组件的 Java 应用程序 (Swing)。

该技巧依赖于 jdk 中的一些 sun.awt 类来检索 AWT 容器的句柄并将其传递给 OO 对象:

public static long getHWnd(Component f) {
    ComponentPeer compPeer = f.getPeer();
    if (compPeer == null) {
        return 0;
    }
    if (compPeer instanceof WComponentPeer) {
        return ((WComponentPeer) compPeer).getHWnd();
    }
    // typically we get here if the peer is of class sun.awt.NullComponentPeer
    // (e.g if the Component is a Swing object - apparently these do not have a "peer")
    return -1;
}

这在我搬到 OpenJDK 之前一直有效。

在 Java 11 中,Componet#getPeer 不再可用。

在 OpenJDK 中,WComponentPeer 不能作为旧 sun.awt 类的一部分使用

他们还有其他方法可以在 Java11 中检索该句柄吗?

(或者一种将 OO Writer 组件集成到 Java Swing 应用程序中的更简洁的方法?)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)