Home Integrating Matlab into Java with MatlabEngine
 I am trying to run Matlab scripts with Java to create plots and display them on a GUI built in Java. When I try to run the code from the main JPanel constructor, it works fine, but when I put it inside an ActionListener, I get this exception : java.lang.IllegalStateException: Blocking in Event Dispatch Thread not allowed  Using the startMatlabAsync() gives me the error (I though that might do the trick?). Since my ultimate goal is to have a fully functional GUI from which I can run different scripts, them not working when they are called from an even listener is quite problematic... Here is the code :  try { final String plotPath = "the soon to be plot"; // Future asyncEng = MatlabEngine.startMatlabAsync(); // MatlabEngine eng = asyncEng.get(); String inputPath = "get me data"; String outputPath = "give me plot"; MatlabEngine eng = MatlabEngine.startMatlab(); eng.eval("cd somewhere elso"); eng.eval("plotMe(" + inputPath + ", " + outputPath + ")"); eng.close(); BufferedImage img = ImageIO.read(new File(plotPath)); ImageIcon icon = new ImageIcon(img); JLabel image = new JLabel(icon); MainPanel.this.add(image); } catch (SomeException ex) { ex.printStackTrace(); }  When I put the code inside a an event listener, like this :  private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) { createSomeDataToPlot(); // same code as above } } }  BIG PROBLEMS. Thanks in advance!