Page 1 of 1

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

PostPosted: Mon May 03, 2021 10:32 pm
by lvr123
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   Expand viewCollapse view
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 ?