App designer callback not evaluating

9 次查看(过去 30 天)
I think the problem is that a "valueChanged" callback is not being evaluated when the value changes. How can I force callbacks to be evaluated when promised (it might be a java issue since it goes away after restarting MATLAB? I might need to somehow clear that?)
Here is the problem description
I have a gui I exported from app designer. I wrote a simple callback after exporting. When a user clicks a check box labeled "Monkey GIFs" some buttons on the GUI are set to invisible and are replaced with images. The images have been there the whole time but are set to invisible by default. All the check box does is toggle the visibility and ensure the buttons and the images have opposite visibility.
However, the changes in visibility do not render until after the user interacts with some other feature. I put a "drawnow" in the checkbox callback so I think the problem is that the callback itself is not being evaluated until the next click. The problem is intermittent, and doesn't occur on the first use after restarting MATLAB.
Here is how I create the checkbox
app.MonkeyGIFsCheckBox = uicheckbox(app.AutoBackupTab);
app.MonkeyGIFsCheckBox.ValueChangedFcn = createCallbackFcn(app, @MonkeyGIFsCheckBoxValueChanged, true);
app.MonkeyGIFsCheckBox.Text = 'Monkey GIFs';
app.MonkeyGIFsCheckBox.Position = [29 75 92 22];
app.MonkeyGIFsCheckBox.Value = false;
Here is how I wrote the callback
% Value changed function: MonkeyGIFsCheckBox
function MonkeyGIFsCheckBoxValueChanged(app, event)
value = app.MonkeyGIFsCheckBox.Value;
if value
app.CloseWithoutBackupImage.Visible='on';
app.CloseWithoutBackupImageLabel.Visible='on';
app.PerformBackupImage.Visible='on';
app.PerformBackupImageLabel.Visible='on';
app.CloseWithoutBackupButton.Visible='off';
app.PerformBackupButton.Visible='off';
else
app.CloseWithoutBackupImage.Visible='off';
app.CloseWithoutBackupImageLabel.Visible='off';
app.PerformBackupImage.Visible='off';
app.PerformBackupImageLabel.Visible='off';
app.CloseWithoutBackupButton.Visible='on';
app.PerformBackupButton.Visible='on';
end
drawnow
end
  2 个评论
Mario Malic
Mario Malic 2020-10-21
编辑:Mario Malic 2020-10-22
Edit: italics in my comment is not correct.
This question might be of interest https://uk.mathworks.com/matlabcentral/answers/345697-how-to-add-extra-arguments-to-callback-functions-in-app-designer. It looks like that third argument 'true' doesn't work.
James Johnson
James Johnson 2020-10-24
编辑:James Johnson 2020-10-24
Thanks for taking an interest.
It's not an "extra argument". MATLAB's built in app designer put that "true" in there, it looks like a required positional argument. I had nothing to do with it, and don't need to use extra arguments or share data across callbacks.
Hence, it's irrelevant. I just need to get the callback to actually execute. I think it's a java issue. I'm hoping there's some way to "flush" java. Note: I already use "drawnow" which is unhelpful since the callback doesn't get executed until the user clicks some other element.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by