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

Overview

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:

Examples

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

	//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 programatical changes of layout or control size.

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

We are also pleased to provide you more support in direct contact with our engineers at support@javonet.com