MATLAB: How to get the handles structure from a Callback that doesn’t include the original GUI figure(hObject)

guideMATLAB

I'm using a jRangeSlider to set the start and stop times for a video clip.
The Opening Fcn is this:
jRangeSlider = com.jidesoft.swing.RangeSlider(0,20, 4, 6);
handles.jRangeSlider = javacomponent(jRangeSlider, [55,50,300,75], hObject);
set(handles.jRangeSlider, 'StateChangedCallback', @(x, y) slider_Callback(x, y));
I've come to realize that 'StateChangedCallback' just prints out all of the properties of the jRangeSlider before and after the change, and so the callback function isn't directly linked to hObject and handles of the GUI that I placed the slider in.
How can I acquire handles so that I can jRangeSlider.get(High/Low)Value to then set the video frames?
Is setappdata(0, 'handles', handles) a viable option?

Best Answer

Place the callback within the opening function as a nested function. This way, the callback is able to access the handles variable from the opening function without having it as a direct parameter.