Skip to content

WPF & Interop – what about Java Swing?

June 27, 2006
I’m meeting with an ISV tomorrow who has a large Java code investment.
I’m trying to understand if it is possible to embed WPF controls inside of Java (via JNI, etc…).
WPF has invested in interop with a number of technologies:
  • HwndSource – allows you to host WPF content inside of an HWND.
  • <HwndHost /> – allows you to host an HWND inside of WPF content.

Windows Presentation Foundation (formerly code-named "Avalon") provides a rich environment for creating applications. However, when you have a substantial investment in Microsoft Win32 code, it may be more effective, at least in the short-term, to reuse some of that code. There are two basic ways to interoperate Windows Presentation Foundation and Win32 code.

  • Host a Windows Presentation Foundation page in a Win32 window.This allows you, for instance, to use the advanced graphics capabilities of Windows Presentation Foundation within the framework of a standard Win32 window and application.

  • Host a Win32 window on a Windows Presentation Foundation page. This allows you, for instance, to use a custom Win32 control in the context of a Windows Presentation Foundation page.

This document provides an overview of how to interoperate Windows Presentation Foundation and Win32 code. It is accompanied by two detailed walkthroughs, Walkthrough: Hosting a Simple Win32 Control in a Windows Presentation Foundation Application and Walkthrough: Hosting a Windows Presentation Foundation Page in a Win32 Application, which take you through simple working examples of the two scenarios.

  • IFrame/Frame in IE – can host browser apps (.xbap) or XAML pages
  • <Frame />- allows you to host other XAML pages or HTML pages.
Windows Forms <–> WPF
  • ElementHost – allows you to host WPF content inside of a Windows Forms application.
  • <WindowsFormsHost /> – allows you to host a Windows Forms control inside of WPF content.

Snippet from SDK Overview for WindowsForms Interop:

Windows Presentation Foundation and Windows Forms present two different architectures for creating application interfaces. The System.Windows.Forms.Integration namespace provides classes that enable common interoperation scenarios. The two key classes that implement interoperation capabilities are WindowsFormsHost and ElementHost. This topic describes which interoperation scenarios are supported and which scenarios are not supported.


Java Swing <–> WPF (????)
Has anybody built or investigated a way to embed WPF content inside of a Java Swing application?
Does anybody want this ability?
Has anybody built or investigated a way to embed Java Swing content inside of a WPF application?
Does anybody want this ability?
I imagine that HwndSource and HwndHost would likely be used to allow this interopability…

From → WPF

  1. Michael Latta permalink

    At JavaOne this year they mentioned attempts to have the Java VM and the CLR loaded into the same process.  This would be a prerequisite to WPF / Swing interop.  The comments at that time were that there are still issues where the two managed environments thrash.  I believe part of the problem is that the Java VM wants to know how big its heap can grow in advance, and verifies the availability of that RAM, and most likely wants that to be contiguous virtual memory.  On a 64 bit system this would not be an issue, but in a 32 bit world this is going to get tight.  Given that Eclipse uses a native code UI framework, once the two virtual environments can co-locate it should be possible to let the WPF side have all the UI control.  Then the rendering of Swing content would be virtual.  It is currently double buffered and the JDK 6 release coming out uses this to do window refreshes without application involvement.  The next logical step would be to use WPF to provide that retained image of hte Swing UI and allow swing to update the retained image as needed.

  2. Michael permalink

    I migrated to .Net from Java and one thing that I avoided like the plague was swing/AWT development (desktop client or applet based). I don\’t know if I was biased against it because I saw it at its worse, or if I was just too lazy to put the effort into becoming proficient with it.
    Either way it goes, I\’ve always had the impression from other Java developers that java based UI were a lost cause.
    If Swing to WPF interop comes as a side-effect to some other effort, great. Otherwise, I\’d guess that it is too much of an edge case for a major focus on getting it to work.

  3. Unknown permalink

    Amberdigital Branch,Southern Stars Enterprises Co is specializing in the development and manufacturing of mp4 advertisement players, SD card players and advertisement LCD displays. Established in 1996, we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

    amberdigital Contact Us
    Southern Stars Enterprises Co (Hong Kong Office)
    Add:3 Fl, No.2, Lane 2, Kam Tsin Tsuen, Sheung Shui, Hong Kong
    Tel:+852 2681 4099
    Fax:+852 2681 4586
    Southern Stars Enterprises Co (Shenzhen Office)
    Add:DE, 16/F, Building 2, Nanguo Tower, Sungang Road, Shenzhen, China
    Tel:+86 755 2592 9100
    Fax:+86 755 2592 7171[aieffebagfcdbg]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: