1

I need to import a plot graph from matlab into java swing GUI? Is there any way to do it?

3 Answers 3

2

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 as JLabel) or

  • draw it in a component's paintComponent() method using drawImage() .

Sign up to request clarification or add additional context in comments.

3 Comments

+1 for non-interactive plots this is definitively the easiest way.
The Matlab print() function, using the -d option, can export a figure to image files or the system clipboard in various formats. See "doc print".
Sure beats doing graphs with a ruler and pencil!!
0

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.

Comments

0

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.

1 Comment

This should work, but it really depends if the Matlab graph was created offline or needs to be created at runtime during the java application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.