4

I have an application written in Java. The application has several UI controls in it (textboxes, grids, buttons, etc.) I need to develop .NET application, which would be able to list UI elements and read text data from them. I have no problem obtaining Window handle for Java app, but after that I am stuck.

Java app is third-party and can't be modified in any way. I have zero experience in Java, but strong experience in C#. I tried using Java Access Bridge, but it does not seem to work. As far as I understand, Java app needs to support Java Accessibility API, which it probably does not.

Please share your experience with similar task or simply point me in a right direction.

How to enumerate/read UI controls from outside Java VM?

Roman C
  • 49,761
  • 33
  • 66
  • 176
J-M
  • 1,207
  • 11
  • 18

3 Answers3

3

I found the solution. It seems Java Access Bridge is still supported for my java app, but I couldn't make it work at first.

Tips:

  1. WinForms app is required to use Java Access Bridge API and I was trying to access it from console .NET app. (WPF should be supported too, but I didn't test it)

  2. Windows_run method should be called inside form's constructor. Just before you access any other API functions.

  3. Java Access Bridge should be enabled in file accessibility.properties (folder: C:\Program Files\Java\jre7\lib)

J-M
  • 1,207
  • 11
  • 18
0

The only way is to convert .NET -> Java or Java -> .NET is by hand or may be there's some commercial converters. You can run the Java code inside the Java VM by creating the instance but there's no such interop to Java it's not COM. However, this could be useful.

Roman C
  • 49,761
  • 33
  • 66
  • 176
0

You'll need to do something like the code in this StackOverflow example to get all the child windows, then use WM_GETTEXT to read the text data.

Community
  • 1
  • 1
prprcupofcoffee
  • 2,950
  • 16
  • 20
  • The fact that the application is in Java shouldn't matter - it's still running on Windows, and needs to call Windows APIs to generate the basic UI elements like text boxes and so forth. – prprcupofcoffee Nov 13 '12 at 22:31
  • 4
    If that would be this easy... Java is running in VM and drawing UI elements by itself. I don't think it uses Windows API for UI drawing (except window title and minimize/maximize/close buttons). At least UIA Verify tool shows nothing, except mentioned above. – J-M Nov 13 '12 at 22:59