Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Problems with Java from Matlab

Subject: Problems with Java from Matlab

From: Pascal Steiss

Date: 29 Aug, 2009 14:54:12

Message: 1 of 2

Hi All!

I wrote a couple of classes in Java.
If I start the program from console, it works fine.
The Main class is a descendant from JFrame.

If I want to create the object in Matlab, I see an empty JFrame form -
without contents (which is a descendent of JPanel)

Does anyone have any ideas?


-- snip --
public class Main extends JFrame {
     protected static ODView myODView;
     protected boolean mode3D;

     /** Creates a new instance of Main */
     public Main() {

      * @param args the command line arguments
     public static void main(String[] args) {
          Main g = new Main();
          myODView = new ODView2D();
          double myData[][] = new double[55][55];
          Random myRandom = new Random();
          for (int i=0; i<55; i++)
              for (int j=0; j<55; j++) {
                 myData[i][j] = myRandom.nextInt();

     protected void Init() {
         mode3D = false;

     public void Set3D() {
         if (mode3D == false) {

             mode3D = true;


     public void Set2D() {
         if (mode3D == true) {
             myODView = new ODView2D();
             mode3D = false;

     public void SetData(double[][] newData) {
-- snap --

Subject: Problems with Java from Matlab

From: Yair Altman

Date: 29 Aug, 2009 20:28:03

Message: 2 of 2

Your GUI actions in main() probably need to be done asynchronously, on the EDT. This may solve a threading race-condition that may be the cause of your problem. There are plenty of examples and explanations online. Here's one snippet:

import java.awt.EventQueue;
import javax.swing.*;
public class B
  JFrame f;
    f = new JFrame();
  public static void main(String[] args)
    EventQueue.invokeLater(new Runnable()
      public void run()
        B b = new B();

Yair Altman

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us