No, there's no mixing of J# and Windows Forms components

25. May 2006 09:56 by Jaguilar in General  //  Tags: ,   //   Comments (0)

We have been aware of that fact for a while, but we tried anyway - and it doesn't work. The main issue is that the components were implemented separately, and respond to different object hierarchies. Windows Forms receive components that extend the System.Windows.Forms.Control class, while Java containers receive objects that extend from javax.swing.JComponent. This causes an incompatibility, as the code will not even compile when you add an object from the "other" hierarchy, as shown in the following example. Trying to compile this code:

      JFrame frame = new JFrame("HelloWorldSwing");
      ComboBox cb = new ComboBox();

will give you this compilation error:

      Cannot find method 'add(System.Windows.Forms.ComboBox)' in 'java.awt.Container'

The exact same thing happens when you try to add a J# Component to a Windows Form. There are of course technical reasons for this, like the fact that the J# runtime was developed independently, thus components expect a different environment when being drawn, and that it uses a different event handling mechanism (based on Java instead of .NET). But it is a bummer not being able to use a JTable and, for example, a DateTimePicker side-by-side.