Clean way to get an OO Writer container into a Java app

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
lvr123
Posts: 1
Joined: Mon May 03, 2021 7:03 pm

Clean way to get an OO Writer container into a Java app

Post by lvr123 »

Hi,
I wrote a couple of years ago a Java application (Swing) incorporating an OpenOffice Writer component.
The trick relied on some sun.awt classes from the jdk to retrieve the AWT container's handle and pass it to the OO objects:

Code: Select all

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;
}
This used to work until I moved to OpenJDK. I tested with OpenJDK 8 and 11.
They don't have those old sun.awt classes, which breaks the code.

Is they any new or cleaner way to integrate a OO Writer component into a Java Swing application ?
Post Reply