<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: JGraph in Matlab figures	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jgraph-in-matlab-figures</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Mon, 09 May 2022 08:39:56 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-514083</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 09 May 2022 08:39:56 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-514083</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-514082&quot;&gt;mrv&lt;/a&gt;.

The version of JGraph that you downloaded uses a newer version of Java (11) than the one that Matlab supports (8). You need to either (1) find an earlier version of JGraph that uses Java 8 (or earlier), or alternatively (2) make Matlab use Java 11 (or later) run-time engine (JRE) . Among these two alternatives, #1 is safer and easier.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-514082">mrv</a>.</p>
<p>The version of JGraph that you downloaded uses a newer version of Java (11) than the one that Matlab supports (8). You need to either (1) find an earlier version of JGraph that uses Java 8 (or earlier), or alternatively (2) make Matlab use Java 11 (or later) run-time engine (JRE) . Among these two alternatives, #1 is safer and easier.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: mrv		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-514082</link>

		<dc:creator><![CDATA[mrv]]></dc:creator>
		<pubDate>Mon, 09 May 2022 04:00:29 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-514082</guid>

					<description><![CDATA[hello,
I used MATLAB 2019b update9, I have add jgraphx.jar to javaclassapth, and restart matlab, but still got errors below:
&lt;pre&gt;
Warning: A Java exception occurred trying to load the com/mxgraph/view/mxGraph class:
Java exception occurred:
java.lang.UnsupportedClassVersionError: com/mxgraph/view/mxGraph has been compiled by a more recent version of
the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions
up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.mathworks.jmi.OpaqueJavaInterface.findClass(OpaqueJavaInterface.java:137)
Error using javaObjectEDT
No class com.mxgraph.view.mxGraph can be located on the Java class path
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>hello,<br />
I used MATLAB 2019b update9, I have add jgraphx.jar to javaclassapth, and restart matlab, but still got errors below:</p>
<pre>
Warning: A Java exception occurred trying to load the com/mxgraph/view/mxGraph class:
Java exception occurred:
java.lang.UnsupportedClassVersionError: com/mxgraph/view/mxGraph has been compiled by a more recent version of
the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions
up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.mathworks.jmi.OpaqueJavaInterface.findClass(OpaqueJavaInterface.java:137)
Error using javaObjectEDT
No class com.mxgraph.view.mxGraph can be located on the Java class path
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-510220</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 09 Mar 2021 19:18:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-510220</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-510216&quot;&gt;mukesh Muthu&lt;/a&gt;.

Perhaps you tried to access the class before you used &lt;code&gt;javaaddpath&lt;/code&gt; to add the JAR file to the classpath. If Matlab fails to find a class, then it will not be able to access it even after adding to the classpath - the only solution is to restart Matlab and to remember to add the JAR file to the classpath before trying to access the class.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-510216">mukesh Muthu</a>.</p>
<p>Perhaps you tried to access the class before you used <code>javaaddpath</code> to add the JAR file to the classpath. If Matlab fails to find a class, then it will not be able to access it even after adding to the classpath &#8211; the only solution is to restart Matlab and to remember to add the JAR file to the classpath before trying to access the class.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: mukesh Muthu		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-510216</link>

		<dc:creator><![CDATA[mukesh Muthu]]></dc:creator>
		<pubDate>Tue, 09 Mar 2021 19:02:07 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-510216</guid>

					<description><![CDATA[i get the following error , im using matlab 2016b-64bit
if i use
&lt;pre lang=&quot;matlab&quot;&gt;
graph = com.mxgraph.view.mxGraph
Undefined variable &quot;com&quot; or class &quot;com.mxgraph.view.mxGraph&quot;.
&lt;/pre&gt;
if i use
&lt;pre lang=&quot;matlab&quot;&gt;
graph = javaObjectEDT(&#039;com.mxgraph.view.mxGraph&#039;);
Error using javaObjectEDT
No class com.mxgraph.view.mxGraph can be located on the Java class path
&lt;/pre&gt;
i checked the dynamic javapath and it has the mentioned jar file listed]]></description>
			<content:encoded><![CDATA[<p>i get the following error , im using matlab 2016b-64bit<br />
if i use</p>
<pre lang="matlab">
graph = com.mxgraph.view.mxGraph
Undefined variable "com" or class "com.mxgraph.view.mxGraph".
</pre>
<p>if i use</p>
<pre lang="matlab">
graph = javaObjectEDT('com.mxgraph.view.mxGraph');
Error using javaObjectEDT
No class com.mxgraph.view.mxGraph can be located on the Java class path
</pre>
<p>i checked the dynamic javapath and it has the mentioned jar file listed</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Vivek Shankar		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-404818</link>

		<dc:creator><![CDATA[Vivek Shankar]]></dc:creator>
		<pubDate>Wed, 12 Apr 2017 19:43:26 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-404818</guid>

					<description><![CDATA[Hello,
Thanks for the excellent tutorial. After spending some time with the JgraphX api, I am able to accomplish most of the things I need. One thing I am unable to get my head around is the saving and loading of a JGraph objects in Matlab. I had tried to use the encode and decode codecs in the JgraphX library and then to write as an XML output, but for some reason the codecs dint seem to work =-  encoding the graph-model results in an empty variable. I was trying :

   &lt;pre lang=&quot;matlab&quot;&gt;
codec = com.mxgraph.io.mxCodec;
mxUtils = com.mxgraph.util.mxUtils;

graph_xml = mxUtils.getXml(codec.encode(graph.getModel()))
mxUtils.writeFile(graph_xml,&#039;test.xml&#039; );

 &lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Hello,<br />
Thanks for the excellent tutorial. After spending some time with the JgraphX api, I am able to accomplish most of the things I need. One thing I am unable to get my head around is the saving and loading of a JGraph objects in Matlab. I had tried to use the encode and decode codecs in the JgraphX library and then to write as an XML output, but for some reason the codecs dint seem to work =-  encoding the graph-model results in an empty variable. I was trying :</p>
<pre lang="matlab">
codec = com.mxgraph.io.mxCodec;
mxUtils = com.mxgraph.util.mxUtils;

graph_xml = mxUtils.getXml(codec.encode(graph.getModel()))
mxUtils.writeFile(graph_xml,'test.xml' );

 </pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-352286</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 02 Jul 2015 12:35:02 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-352286</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-352283&quot;&gt;Sam Roberts&lt;/a&gt;.

@Sam - thanks for the detailed feedback :-)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-352283">Sam Roberts</a>.</p>
<p>@Sam &#8211; thanks for the detailed feedback 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Sam Roberts		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-352284</link>

		<dc:creator><![CDATA[Sam Roberts]]></dc:creator>
		<pubDate>Thu, 02 Jul 2015 12:17:49 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-352284</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-352283&quot;&gt;Sam Roberts&lt;/a&gt;.

PS - I don&#039;t know if you&#039;ve downloaded it yet, but the prerelease of R2015b does actually contain a new suite of functionality for graphs. There&#039;s a new graph object, and it has lots of great functionality for graph-theoretic work, such as shortest paths and minimum spanning trees. It also contains graph layout and plotting functions - unfortunately, at the moment these are not even 1% as nice looking as JGraph. But I&#039;m sure they&#039;ll be improving that in future releases.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-352283">Sam Roberts</a>.</p>
<p>PS &#8211; I don&#8217;t know if you&#8217;ve downloaded it yet, but the prerelease of R2015b does actually contain a new suite of functionality for graphs. There&#8217;s a new graph object, and it has lots of great functionality for graph-theoretic work, such as shortest paths and minimum spanning trees. It also contains graph layout and plotting functions &#8211; unfortunately, at the moment these are not even 1% as nice looking as JGraph. But I&#8217;m sure they&#8217;ll be improving that in future releases.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Sam Roberts		</title>
		<link>https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures#comment-352283</link>

		<dc:creator><![CDATA[Sam Roberts]]></dc:creator>
		<pubDate>Thu, 02 Jul 2015 12:14:10 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5895#comment-352283</guid>

					<description><![CDATA[Hi Scott and Yair,

I&#039;ve used JGraphX quite a bit within MATLAB UIs, and have a couple of suggestions based on my experience.

i) When you create the mxGraphComponent, I&#039;d make sure to explicitly put it on the EDT, as you&#039;ve done in your post for the mxGraph. In other words, rather than

&lt;pre lang=&quot;matlab&quot;&gt;graphComponent = com.mxgraph.swing.mxGraphComponent(graph);&lt;/pre&gt;

I&#039;d write &lt;pre lang=&quot;matlab&quot;&gt;graphComponent = javaObjectEDT(&#039;com.mxgraph.swing.mxGraphComponent&#039;, graph);&lt;/pre&gt;

That should make sure there are no threading issues.

ii) Rather than making a JPanel, adding the graphcomponent to the JPanel, and then using &lt;i&gt;&lt;b&gt;javacomponent&lt;/b&gt;&lt;/i&gt; to insert the JPanel into a figure as you do above, I would just make a regular MATLAB uipanel in the figure, and then use &lt;i&gt;&lt;b&gt;javacomponent&lt;/b&gt;&lt;/i&gt; to place the graphcomponent into the uipanel. A uipanel is basically a JPanel anyway, but again it has wrappers that will manage any threading issues that might arise.

iii) I&#039;ve found that, by default, the graphcomponent contains several mouse listeners that interfere with callbacks that I&#039;m trying to create. So I&#039;ve found it useful to remove them all before creating my own. You can do this using something like the following code:

&lt;pre lang=&quot;matlab&quot;&gt;
graphControl = graphComponent.getGraphControl;
mls  = graphControl.getMouseListeners;
mmls = graphControl.getMouseMotionListeners;
for i = 1:numel(mls)
    graphControl.removeMouseListener(mls(i))
end
for i = 1:numel(mmls)
    graphControl.removeMouseMotionListener(mmls(i))
end
&lt;/pre&gt;

iv) Instead of &lt;code&gt;javax.swing.SwingUtilities.isRightMouseButton(eventData)&lt;/code&gt;, you can just use &lt;code&gt;eventData.getButton&lt;/code&gt;, which equals 1 for the left button or 3 for the right button. You can also use &lt;code&gt;eventData.isShiftDown&lt;/code&gt; or &lt;code&gt;eventData.isControlDown&lt;/code&gt; to detect key modifiers on the mouse click.

Hope that&#039;s useful for people!

Sam]]></description>
			<content:encoded><![CDATA[<p>Hi Scott and Yair,</p>
<p>I&#8217;ve used JGraphX quite a bit within MATLAB UIs, and have a couple of suggestions based on my experience.</p>
<p>i) When you create the mxGraphComponent, I&#8217;d make sure to explicitly put it on the EDT, as you&#8217;ve done in your post for the mxGraph. In other words, rather than</p>
<pre lang="matlab">graphComponent = com.mxgraph.swing.mxGraphComponent(graph);</pre>
<p>I&#8217;d write </p>
<pre lang="matlab">graphComponent = javaObjectEDT('com.mxgraph.swing.mxGraphComponent', graph);</pre>
<p>That should make sure there are no threading issues.</p>
<p>ii) Rather than making a JPanel, adding the graphcomponent to the JPanel, and then using <i><b>javacomponent</b></i> to insert the JPanel into a figure as you do above, I would just make a regular MATLAB uipanel in the figure, and then use <i><b>javacomponent</b></i> to place the graphcomponent into the uipanel. A uipanel is basically a JPanel anyway, but again it has wrappers that will manage any threading issues that might arise.</p>
<p>iii) I&#8217;ve found that, by default, the graphcomponent contains several mouse listeners that interfere with callbacks that I&#8217;m trying to create. So I&#8217;ve found it useful to remove them all before creating my own. You can do this using something like the following code:</p>
<pre lang="matlab">
graphControl = graphComponent.getGraphControl;
mls  = graphControl.getMouseListeners;
mmls = graphControl.getMouseMotionListeners;
for i = 1:numel(mls)
    graphControl.removeMouseListener(mls(i))
end
for i = 1:numel(mmls)
    graphControl.removeMouseMotionListener(mmls(i))
end
</pre>
<p>iv) Instead of <code>javax.swing.SwingUtilities.isRightMouseButton(eventData)</code>, you can just use <code>eventData.getButton</code>, which equals 1 for the left button or 3 for the right button. You can also use <code>eventData.isShiftDown</code> or <code>eventData.isControlDown</code> to detect key modifiers on the mouse click.</p>
<p>Hope that&#8217;s useful for people!</p>
<p>Sam</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
