# Jmathplot via JavaCall.jl

**URL:** <https://discourse.julialang.org/t/jmathplot-via-javacall-jl/69686>\
**Category:** Visualization\
**Tags:** plotting, java\
**Created:** [October 13, 2021, 2:24pm UTC](https://discourse.julialang.org/t/jmathplot-via-javacall-jl/69686 "2021-10-13T14:24:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [October 13, 2021, 2:24pm UTC](https://discourse.julialang.org/t/jmathplot-via-javacall-jl/69686/1 "2021-10-13T14:24:11Z")

</div>

Hi,  
would be glad if someone could give a hand with the example from  
[https://github.com/yannrichet/jmathplot](https://github.com/yannrichet/jmathplot).  
jmathplot.jar is in [https://github.com/yannrichet/jmathplot/tree/master/dist](https://github.com/yannrichet/jmathplot/tree/master/dist)  
Got lost in the calling syntax.  
Thx

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [October 13, 2021, 7:35pm UTC](https://discourse.julialang.org/t/jmathplot-via-javacall-jl/69686/2 "2021-10-13T19:35:35Z")

</div>

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
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](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6ad80c0d8287e108330f31975c77309941cddd4.png)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [October 13, 2021, 7:53pm UTC](https://discourse.julialang.org/t/jmathplot-via-javacall-jl/69686/3 "2021-10-13T19:53:03Z")

</div>

Icons: [https://github.com/yannrichet/jmathplot/tree/master/src/main/resources/org/math/plot/icons](https://github.com/yannrichet/jmathplot/tree/master/src/main/resources/org/math/plot/icons)  
jmathplot.jar: [https://github.com/yannrichet/jmathplot/blob/master/dist/jmathplot.jar](https://github.com/yannrichet/jmathplot/blob/master/dist/jmathplot.jar)  
jmathio.jar: [https://github.com/yannrichet/jmathio/blob/master/dist/jmathio.jar](https://github.com/yannrichet/jmathio/blob/master/dist/jmathio.jar)  
jmatharray.jar: [https://github.com/yannrichet/jmatharray/blob/master/dist/jmatharray.jar](https://github.com/yannrichet/jmatharray/blob/master/dist/jmatharray.jar)

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

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [October 13, 2021, 8:37pm UTC](https://discourse.julialang.org/t/jmathplot-via-javacall-jl/69686/4 "2021-10-13T20:37:57Z")

</div>

Awesome, thank you!
