Embedding .NET User Controls in Java AWT, Swing or JavaFX

You are browsing legacy Javonet 1.5 (Java<>.NET bridge for Windows) documentation. Use the left side menu or click here to switch to latest Javonet 2.0 documentation. Javonet 2.0 allows you to use any module from JVM, CLR, Netcore, Python, Ruby, Perl, NodeJS on Windows, Linux and MacOs from any application created in Java, Clojure, Groovy, Kotlin, C#, F#, J#, VB.NET, Python, Perl, Ruby, JavaScript, TypeScript, C++ and GoLang

With Javonet you can very easily embed any .NET WinForms or WPF user control in Java. Embedded control can be placed within any Java layout component like Panels, Borders, Frames etc… in order to present the control side by side within the Java desktop application.

You can easily fully interact with all the features of .NET UI control invoking any methods, retrieving results or subscribing the events and callbacks which will be triggered when user interacts with .NET control.

The control will automatically move and scale with Java window. The user experience is completely seamless and transparent for end-user. Due to the fact that .NET controls are rendered and executed by .NET framework the performance of the control is native like using regular .NET application.

You can see the sample project in action on this video


To embed user control in Java UI you need to wrap the control in NControlContainer class and add to your layout:

// Todo: activate Javonet

//  create new instance of your WPF control
NObject userControl = Javonet.New("Javonet.WpfUserControlSample.UserControl1");
// wrap the control with NControlContainer
NControlContainer dotNetUserControl = new NControlContainer(userControl);

// create your layout
JPanel panel = new JPanel();

// add wrapper to your layout
panel.add(dotNetUserControl, BorderLayout.EAST);
//this.add(panel, BorderLayout.CENTER);

In order to subscribe any event expose by the control just reference to the control instance NObject class:

userControl.addEventListener("ButtonClicked", new NEventListener() {
    public void eventOccurred(Object[] arguments) {
        //do the event handler work

Starting 1.4hf34 we have exposed updated revalidate method which allows you to refresh the control layout after programmatic changes of layout or control size

dotNetUserControl.setPreferredSize(new Dimension(200, 300));