Comments on: Matlab callbacks for Java events in R2014a https://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a Charting Matlab's unsupported hidden underbelly Thu, 02 May 2024 08:00:01 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-399068 Thu, 26 Jan 2017 08:27:21 +0000 https://undocumentedmatlab.com/?p=4814#comment-399068 You can either use the Java SimpleDateFormat class to convert the date format into your desired output format (read the Java docs online to see how to do this), or use Matlab’s datenum and datestr functions with the appropriate format specifiers (read the corresponding Matlab docs to see how to do this).

]]>
By: Muthukumarhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-399064 Thu, 26 Jan 2017 06:57:30 +0000 https://undocumentedmatlab.com/?p=4814#comment-399064 How do I get delimiter of the date format ?

example :
system foramt – 1/23/2017
Get Output from your script – mm dd,yyyy

I need output like – dd/mm/yyyy

Thanks in Advance

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-361419 Thu, 12 Nov 2015 22:35:56 +0000 https://undocumentedmatlab.com/?p=4814#comment-361419 JAR files contain Java classes, not Matlab figures. The entire blog here discusses Matlab.

]]>
By: Matthew Harrisonhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-361412 Thu, 12 Nov 2015 21:50:35 +0000 https://undocumentedmatlab.com/?p=4814#comment-361412 Is there a clean way to do it from when your loading a .jar file?

For example I have a .jar file called test.jar
I call it like jFrame=test(); after adding it to the dynamic Java classpath
but that jFrame doesnt have properties to getWindow or JavaFrame?

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-361341 Wed, 11 Nov 2015 19:37:01 +0000 https://undocumentedmatlab.com/?p=4814#comment-361341
jFigPeer = get(handle(gcf),'JavaFrame');
jFrame = handle(jFigPeer.fHG2Client.getWindow, 'CallbackProperties');
jFrame.WindowClosingCallback = @myCallback;
]]>
By: Matthew Harrisonhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-361336 Wed, 11 Nov 2015 17:30:53 +0000 https://undocumentedmatlab.com/?p=4814#comment-361336 Does anyone know how to get the window events like window closing using this method?

]]>
By: Dave Brownhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-355803 Mon, 24 Aug 2015 17:49:57 +0000 https://undocumentedmatlab.com/?p=4814#comment-355803 I ran into a problem from using java 7 that took a while to discover so I thought I’d share it. Hopefully it helps those with the same problem in the future.

>> jScrollbar = javaObjectEDT('javax.swing.JScrollBar');
>> hjScrollbar = handle(jScrollbar,'CallbackProperties');
>> set(hjScrollbar, 'StateChangedCallback', callback);
Error using javahandle_withcallbacks.javax.swing.JScrollBar/set
The name 'StateChangedCallback' is not an accessible property for an instance of class 'javax.swing.JScrollBar'. 
 
>> ver
...
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
...

The problem is java 7 has changed the interface to the component and it is no longer a state change event but an adjustment event.
(see http://www.java2s.com/Code/Java/Swing-JFC/ListeningforScrollbarValueChangesinaJScrollPaneContainer.htm). It is corrected by using hjScroll.AdjustmentValueChangedCallback in this example. Be on the lookout for these types of changes in the java interface.

]]>
By: Danielle Dhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-343143 Sat, 03 Jan 2015 21:59:56 +0000 https://undocumentedmatlab.com/?p=4814#comment-343143 Running Matlab 2014b, I had the same problem the Sean Lynch posted:

>> h_evt = handle(evt, 'CallbackProperties');
>> set(h_evt,'TestEventCallback',@(h,e)disp(h))
>> get(h_evt)
                    Class: [1x1 java.lang.Class]
        TestEventCallback: @(h,e)disp(h)
    TestEventCallbackData: []
 
>> evt.notifyMyTest
	javahandle_withcallbacks.EventTest

But trying something like

>> set(h_evt,'TestEventCallback',@(h,e)disp('test'))
>> h_evt.notifyMyTest
test

demonstrates that it is working. One step at a time.

Thank you! This article helped a lot as well as the previous article: https://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-331527 Sat, 13 Sep 2014 16:40:13 +0000 https://undocumentedmatlab.com/?p=4814#comment-331527 This is due to the difference between running platforms and/or Matlab releases. If you’d like my assistance in helping you on your specific platform, contact me offline for a consulting proposal.

]]>
By: Sean Lynchhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-331451 Fri, 12 Sep 2014 15:59:38 +0000 https://undocumentedmatlab.com/?p=4814#comment-331451 Thank you, using the static path worked (but I had to use “javaclasspath.txt” in the prefdir() instead). The callback now sets, but the value looks wrong:

>> set(evt,'TestEventCallback',@(h,e)disp(h))
>> get(evt)
                    Class: [1x1 java.lang.Class]
        TestEventCallback: @(h,e)disp(h)
    TestEventCallbackData: []
 
>> evt.notifyMyTest
	javahandle_withcallbacks.nujira.EventTest

Your example showed:

>> set(evt,'TestEventCallback',@(h,e)disp(h))
>> get(evt)
	Class = [ (1 by 1) java.lang.Class array]
	TestEventCallback = [ (1 by 1) function_handle array]
	TestEventCallbackData = []
 
>> evt.notifyMyTest   % invoke Java event
              0.0009765625   % Matlab callback

We are nearly there.
PS: I do have a copy of your book which has been very helpful.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-331449 Fri, 12 Sep 2014 15:22:35 +0000 https://undocumentedmatlab.com/?p=4814#comment-331449 @Sean – as I explained here, you need to place the relevant class folder/JAR in Matlab’s static Java classpath.

]]>
By: Sean Lynchhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-331448 Fri, 12 Sep 2014 15:12:31 +0000 https://undocumentedmatlab.com/?p=4814#comment-331448 I’ve just run the above example and it works without the update; Have MATLAB patched R2014a. my version reports 8.3.0.532 (R2014a)?

Also the EventTest example does not work/without the update:

>> evt = javaObjectEDT(nujira.EventTest)
evt =
nujira.EventTest@64902cf8
 
>> evt = handle(evt, 'CallbackProperties')
evt =
	javahandle_withcallbacks.nujira.EventTest
 
>> get(evt)
                    Class: [1x1 java.lang.Class]
        TestEventCallback: []
    TestEventCallbackData: []
 
>> set(evt,'TestEventCallback',@(h,e)disp(h))
java.lang.NullPointerException
	at com.mathworks.jmi.bean.MatlabBeanInterface.addCallback(MatlabBeanInterface.java:484)
	at com.mathworks.jmi.bean.MatlabCallbackInterface.addCallback(MatlabCallbackInterface.java:130)

Any pointers?

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-324859 Wed, 14 May 2014 20:25:16 +0000 https://undocumentedmatlab.com/?p=4814#comment-324859 Maybe both, I don’t know…

For the record, I miss UDD’s ability to dynamically control/add class properties (schema.prop et al) in run time. It’s causing me a lot of headaches migrating some of my code to HG2.

]]>
By: Donn Shullhttps://undocumentedmatlab.com/blog_old/matlab-callbacks-for-java-events-in-r2014a#comment-324858 Wed, 14 May 2014 20:18:52 +0000 https://undocumentedmatlab.com/?p=4814#comment-324858 This change “enforces” using callbacks in a way which prevents memory leaks. But since this was essentially undocumented all along this change opens up a more interesting question. Is this change part of under the hood reorganizations in preparation for HG2? Or possibly a movement towards aligning java support with MCOS and away from UDD?

]]>