Developing UI Component Classes | post-setup initialisation method ?

4 ビュー (過去 30 日間)
Amos 2021 年 2 月 1 日
回答済み: Greg 2021 年 4 月 15 日
Regarding classes derived from matlab.ui.componentcontainer.ComponentContainer:
¿Does there exist (or is there a way of defining) a method which executes:
  • once only;
  • after the setup method;
  • before the update method?
Motivation is (irreversible) object initialisation conditional on one or more property values passed to the constructor.
To this end, the setup method is unsuitable since
"Any property values passed as name-value pair arguments to the UI component's constructor method are assigned after the setup method executes."
The update method is by definition, not a one-shot method.

回答 (1 件)

Greg 2021 年 4 月 15 日
Your part about "before the update method" is a moving target. The update method is supposed to execute during a graphics flush (i.e., drawnow or pause calls). So depending on the code, your update method might occur more often than another.
In my componentcontainers, I've found the update method completely useless (and even detrimental). I leave it blank, and build my own method named draw that I can call if and when I want it to execute. A trick I use to accomplish the "do stuff before update" is a "skipUpdate" property. Define it as true by default, then the bottom of the constructor sets it to false. Inside the update method, the very first thing is if obj.skipUpdate;return;end.

Community Treasure Hunt

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

Start Hunting!

Translated by