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

Thread Subject:
SWT GUI form Matlab / importing Java classes (II)

Subject: SWT GUI form Matlab / importing Java classes (II)

From: Sturla Molden

Date: 23 Jun, 2004 18:56:40

Message: 1 of 1

It seems there was one combination I had not tried, using static
classpath and relative paths. When the following was added to
classpath.txt, I could finally import my SWT-based GUI classes:

/Program Files/Java SDK/eclipse-SDK-2.1.3-win32/eclipse/plugins/org.eclipse.ui_2.1.1/ui.jar
/Program Files/Java SDK/eclipse-SDK-2.1.3-win32/eclipse/plugins/org.eclipse.core.boot_2.1.3/boot.jar
/Program Files/Java SDK/eclipse-SDK-2.1.3-win32/eclipse/plugins/org.eclipse.ui.workbench_2.1.3/workbench.jar
/Program Files/Java SDK/eclipse-SDK-2.1.3-win32/eclipse/plugins/org.eclipse.swt.win32_2.1.3/ws/win32/swt.jar
/Program Files/Java SDK/eclipse-SDK-2.1.3-win32/eclipse/plugins/org.eclipse.core.runtime_2.1.1/runtime.jar
/Program Files/Java SDK/eclipse-SDK-2.1.3-win32/eclipse/plugins/org.eclipse.jface_2.1.3/jface.jar

Windows-style paths (with backslashes, as I do in Java), Matlab7's
dynamic classpath, or specifying the drive letter caused the Java
class import to fail.

In addition, the following was added to librarypath.txt:
/Program Files/Java SDK/eclipse-SDK-2.1.3-win32/eclipse/plugins/org.eclipse.swt.win32_2.1.3/os/win32/x86

With this settings, Matlab did import the SWT classes!

Here is SWT HelloWorld in Java

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
public class Hello {
   public static void main(String[] args) {
      Display display = new Display();
      Shell shell = new Shell(display);
      Label label = new Label(shell, SWT.NONE);
      label.setText("Hello, World!");
      shell.pack();
      label.pack();
      shell.open();
      while(!shell.isDisposed())
          if(!display.readAndDispatch())
              display.sleep();
      display.dispose();
      label.dispose();
   }
}

and in Matlab:

function Hello
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
display = Display;
shell = Shell(display);
label = Label(shell,SWT.NONE);
label.setText('Hello, World!');
shell.pack;
label.pack;
shell.open;
while(~shell.isDisposed)
    if(display.readAndDispatch)
        display.sleep;
    end
end
display.dispose;
label.dispose;


It is possible to create a Java SWT GUI from Matlab
after all. :-)


Sturla Molden

Tags for this Thread

No tags are associated with 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