Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a Java frontend for Mathematica. Following examples from J/Link guide and looking around the API manual I came up with this code:

public class Mathematica extends MathJFrame {
public Mathematica(String[] args) {

     try {
        ml = MathLinkFactory.createKernelLink(args);
    } catch (MathLinkException e) {
        System.out.println("Fatal error opening link: " + e.getMessage());

    try {


        int result = ml.getInteger();
        System.out.println("2 + 2 = " + result);


    } catch (MathLinkException e) {
        System.out.println("Fatal error opening link: " + e.getMessage());
    } finally {
    private KernelLink ml = null;

public class Graphic extends MathGraphicsJPanel {
   public Graphic() {


I know the link is working because I get 2 + 2 = 4 displayed in console but the panel where the graph output is expected is empty. Also, does J/Link not ship with sample programs anymore?

Thanks for any suggestions.

share|improve this question
Alex, welcome to Mathematica.SE! I must admit I know next to nothing about J/Link, but I noted there's no definition of the graphic1 object in your code. Shouldn't that be there? Also, in what format is graphic1 supposed to get graphics? Might it be a bitmap or so? – Sjoerd C. de Vries Aug 1 '12 at 9:32
Have you seen JLink/tutorial/WritingJavaProgramsThatUseMathematica? It looks like one of the components that is needed is a MathCanvas which I don't see you using. – Sjoerd C. de Vries Aug 1 '12 at 9:52
@SjoerdC.deVries Thank you! From the API manual: "MathGraphicsJPanel is the Swing counterpart to MathCanvas. Use a MathGraphicsJPanel if you are writing a Swing program and a MathCanvas if you are writing an AWT program." I left out the non-mathematica related code such as graphic1 = new Graphic(); and other irrelevant code netbeans adds to reduce question noise. – alex-tech Aug 1 '12 at 10:48
up vote 1 down vote accepted

Looks like it was a bug in Mathematica. I just noticed that I was running 8.0.0 and updated to 8.0.4 and it is working now. Too bad the panel is not interactive. I assume I can rotate and interact with it only when viewing from mathematica's own notebook interface.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.