I need to import a plot graph from matlab into java swing GUI? Is there any way to do it?
This probably isn't the best way to do it... but you could save your data from MATLAB in a convenient format, and then load it in Swing using JFreeChart.
If matlab saves the plot as an image file (say, GIF or PNG or something) then you can use Toolkit.getImage()
or createImage()
to read it in and then
display it on a Swing component either as an
IconImage
(for those components that have icons, such asJLabel
) ordraw it in a component's
paintComponent()
method usingdrawImage()
.
You could also use something like this to evaluate your Matlab script directly in Java and then use the results to create your plot with swing.
Edit:
As Jeff Storey mentioned in his comment, the suggested method is of course used for online evaluation in the Java environment.
If you want to do the computations in Matlab and just display the chart in Java, then I would suggest storing the chart values in a file (e.g. .mat file or just a binary file) and then using a Java chart library (like JFreeChart) to draw the chart.
I wouldn't recommend storing the chart as an image file using Matlab and then loading it from Java to display it. The file will probably be larger and the quality will be much degraded compared to the above mentioned methods.