Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Java GUI inside .NET Form / Visual Studio editor?

My goal is to write a Visual Studio plugin (a VSPackage) for my Java application. I was wondering if it was possible to view some JPanels inside a System.Windows.Forms instance, or rather as an Microsoft.VisualStudio.Editor.

I was thinking an applet but I'm pretty much stuck there...

Is streaming a Swing component as JPEG and displaying it in a Form an applicable idea?

EDIT:

I would really appreciate answers that are more then a "yes"/"no"/"why would you do this?". I made my mind about working this way, so I ask for:

  • A detailed solution for achieving my goal, OR,
  • Good insights/ideas of what my approach should be, OR,
  • A thorough explanation for why it is impossible to achieve.
  • like image 671
    Elist Avatar asked Jul 11 '13 15:07

    Elist


    1 Answers

    ( ) Way of the warrior

    1. Load the JVM from your extension (use jvm.dll).
    2. Implement your own Applet Container. Something like this AppletViewer.
    3. Put the Applet Container inside your native form. This is hard, there are ways to get the Applet Container HWND (In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?), but I am not sure a simple SetParent can do the trick.
    4. Load your Applet.

    ( ) Way of the master

    1. Use NPAPI/NPRuntime, like the browsers do.
    2. Load the npjp2.dll Java Plug-In.
    3. Load your applet.

    (X) The solution adopted was:

    1. Run the VS Plugin part written in Java (like an Applet) with JVM in another process (the standard for Java).
    2. Get the HWND using FindWindow (Win32 API).
    3. Use SetParent (Win32 API) and MoveWindow (Win32 API), to dock the window and resize it.

    I could name it the "the easiest way", but running Java in another process will give you more stability, so this is the "way that works". My only fear about using a window from another process, was the thread that process Windows messages in Java could interfere in Visual Studio. But from what I see, there is nothing to fear.

    :-)

    like image 109
    Marcos Zolnowski Avatar answered Nov 09 '22 23:11

    Marcos Zolnowski