App designer callback not evaluating

10 views (last 30 days)
James Johnson
James Johnson on 21 Oct 2020
Edited: James Johnson on 24 Oct 2020
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 Comments
Mario Malic
Mario Malic on 21 Oct 2020
Edited: Mario Malic on 22 Oct 2020
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 on 24 Oct 2020
Edited: James Johnson on 24 Oct 2020
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.

Sign in to comment.

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!