How to make C ++ code code on Java components

We are developing a physical application, and we would like it to be written in Java, and we also want to use root (root is written in C ++). Root has some interesting graphical capabilities - it can draw very beautiful 3D diagrams, and I think whether these diagrams can be embedded in a Java application.

Is there a way to make C ++ code for drawing like JPanel for example?

Is there a way to pass mouse / keyboard events? - we would like to have some interactivity, for example, rotation of a 3d diagram.

I asked a similar question about embedding a lot of C ++ code (which is not connected with drawing anything) in a Java application (also about the root) here .

0
source share
2 answers

Since SWT is built as a fairly thin shell around your own widgets, it may be easier to work with than with Swing / AWT for your specific task. I understand this particular link is a bit outdated, but it shows how to quickly wrap your own widget.

+1
source

JNI's comment on the question itself seems to be the best way forward - I don't think you want to draw using root as-is; you need to write the interface code between which Java is called through the JNI, which asks "root" to redraw its image with a given size (the corresponding size for the image will be something that only the java component will know). Pass it back to the java component from the JNI call as soon as the 32-bit image data, for example.

I would not assume that you could drag into a java component even in AWT; since it is mainly java wrappers around native components - where the drawing is usually executed in the native component itself (by the operating system, not by Java code).

+1
source

All Articles