Jmathplot via JavaCall.jl

Hi,
would be glad if someone could give a hand with the example from
GitHub - yannrichet/jmathplot: Java interactive 2D and 3D plots (no OpenGL).
jmathplot.jar is in https://github.com/yannrichet/jmathplot/tree/master/dist
Got lost in the calling syntax.
Thx

1 Like

The Java library is not in a great state. First you have to acquire the main jar and it’s two dependencies. You also need to download the icons and put them in a folder “org\math\plot\icons”.

julia> cd("Documents\\Julia\\jmathplot")

julia> readdir()
4-element Vector{String}:
 "jmatharray.jar"
 "jmathio.jar"
 "jmathplot.jar"
 "org"

julia> using JavaCall

julia> JavaCall.addClassPath("./*.jar")

julia> JavaCall.addClassPath(pwd())

julia> JavaCall.init()

julia> Plot2DPanel = @jimport org.math.plot.Plot2DPanel
JavaObject{Symbol("org.math.plot.Plot2DPanel")}

julia> plot = Plot2DPanel()
JavaObject{Symbol("org.math.plot.Plot2DPanel")}(JavaLocalRef(Ptr{Nothing} @0x0000000060bcfd60))

julia> x = Float64[1, 2, 3]
3-element Vector{Float64}:
 1.0
 2.0
 3.0

julia> y = Float64[4, 5, 6]
3-element Vector{Float64}:
 4.0
 5.0
 6.0

julia> jcall(plot, "addLinePlot", jint, (JString, Vector{Float64}, Vector{Float64}), "my plot", x, y)
0

julia> JFrame = @jimport javax.swing.JFrame
JavaObject{Symbol("javax.swing.JFrame")}

julia> frame = JFrame((JString,), "a plot panel")
JavaObject{Symbol("javax.swing.JFrame")}(JavaLocalRef(Ptr{Nothing} @0x0000000060bcfda0))

julia> jcall(frame, "setContentPane", jvoid, (@jimport(java.awt.Container),), plot)

julia> listmethods(frame, "pack")
1-element Vector{JMethod}:
 void pack()

julia> jcall(frame, "pack", jvoid)

julia> jcall(frame, "setVisible", jvoid, (jboolean,), true)

I got a small Window from this that I then I had to manually expand.
image

1 Like

Icons: jmathplot/src/main/resources/org/math/plot/icons at master · yannrichet/jmathplot · GitHub
jmathplot.jar: jmathplot/jmathplot.jar at master · yannrichet/jmathplot · GitHub
jmathio.jar: jmathio/jmathio.jar at master · yannrichet/jmathio · GitHub
jmatharray.jar: jmatharray/jmatharray.jar at master · yannrichet/jmatharray · GitHub

Put the icons in “org/math/plot/icons” and add the root directory to the classpath as I demonstrated above.

1 Like

Awesome, thank you!