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

Creating a macro - Writing a Script - Using the API

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

Postby lvr123 » Mon May 03, 2021 10:32 pm

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   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 ?
lvr123
 
Posts: 1
Joined: Mon May 03, 2021 7:03 pm

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests