jRangeSlider Callback Issue - "Not enough input arguments"

I'm trying to make a GUI with a jRangeSlider such that the frames that play depend on the user moving the sliders. Ultimately, The two knobs are used to determine a specific time frame within a larger video.
For now, I'm having problems with creating the Callback function so that the video figure updates when the slider moves. Either I get a "Not enough input arguments" error (I have no idea why, since everything has three inputs), or I can't get handles from guidata(hObject).
This is OpeningFcn code for the GUI.
jRangeSlider = com.jidesoft.swing.RangeSlider(0,10, 4, 6);
handles.jRangeSlider = javacomponent(jRangeSlider, [55,50,750,75]);
set(handles.jRangeSlider, 'PaintTicks',true, 'PaintLabels',true, 'Background',java.awt.Color.white, ...
'StateChangedCallback',@(hObject, eventdata, handles) rangeslider_Callback(hObject, eventdata, handles));
guidata(hObject, handles)
And this is the callback
function rangeslider_Callback(hObject, eventdata, handles)
low = jRangeSlider.getLowValue();
handles = guidata(hObject);
footage = VideoReader('Time.mp4', 'CurrentTime', low);
image(handles.realvid, readFrame(footage))
I simplified the code quite a bit, so the callback kind of doesn't make sense since it only changes upon moving the lower knob. In reality, it would update based on both, but this is a shorter version with similar functionality.
Thanks!

4 件のコメント

Kairui Zeng
Kairui Zeng 2019 年 5 月 28 日
I'm willing to use a listener or something else as well, it's just that I'm not really familiar with the jRangeSlider properties
Geoff Hayes
Geoff Hayes 2019 年 5 月 28 日
Kairui - why are you using a jRangeSlider instead of the usual horizontal or vertical slider?
Kairui Zeng
Kairui Zeng 2019 年 5 月 28 日
Hi Geoff, my end goal is to have the two knobs of the range slider set the upper and lower limits of a video clip length.
I could definitely use regular sliders, but that means I would need two, which wouldn't be as user-friendly
Kairui Zeng
Kairui Zeng 2019 年 5 月 28 日
A different method I tried that didn't have the "Not enough inputs" error. However, I still don't know how to revert the handles structure back into the original so that I can access the video figure.
%% Opening Fcn part
jRangeSlider = com.jidesoft.swing.RangeSlider(0,10, 4, 6);
handles.jRangeSlider = javacomponent(jRangeSlider, [55,50,750,75]);
set(handles.jRangeSlider, 'PaintTicks',true, 'PaintLabels',true, 'Background',java.awt.Color.white, ...
'StateChangedCallback',@(jRangeSlider, handles) rangeslider_Callback(jRangeSlider, handles));
%% ---
%% Callback part
function rangeslider_Callback(jRangeSlider, handles)
low = jRangeSlider.getLowValue();
handles = guidata(hObject); %% Error occurs here, since handles is no longer the gui structure, but some java thing:
% javax.swing.event.ChangeEvent[source=com.jidesoft.swing.RangeSlider[,0,0,937x93,alignmentX=0.0,alignmentY=0.0,border=,flags=16777512,maximumSize=,minimumSize=,preferredSize=,isInverted=false,majorTickSpacing=0,minorTickSpacing=0,orientation=HORIZONTAL,paintLabels=true,paintTicks=true,paintTrack=true,snapToTicks=false,snapToValue=true]]
footage = VideoReader('Time.mp4', 'CurrentTime', low);
image(handles.realvid, readFrame(footage))

サインインしてコメントする。

 採用された回答

Kairui Zeng
Kairui Zeng 2019 年 5 月 28 日
編集済み: Kairui Zeng 2019 年 5 月 28 日

0 投票

So... I still have a lot to learn.
The 'StateChangedCallback' simply feeds in the object and a changeevent of the jRangeSlider into the Callback fcn. I didn't fully understand the anonymous function use until now, which is why I kept getting the "Not enough inputs" error.
I'll be closing this question since my issue is focused onto something else. Feel free to go visit my other question to help me solve the problem of not have a handles structure within the callback scope.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2019a

質問済み:

2019 年 5 月 28 日

編集済み:

2019 年 5 月 28 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by