Menu en haut à gauche!!

Pour le tester , prenez par exemple l’exemple de la doc :

>>choice = menu('Choose a color','Red','Blue','Green')

Vous verrez que la figure suivante se met bien en haut à gauche de votre écran.

menu r2010b

J’ai contacté mercredi 12 janvier 2011 le support technique de The MathWorks pour en connaitre les raisons… et apparemment il n’y en a pas:

It is not possible to get a handle to the MENU dialog.
The MENU function creates a modal dialog box that returns the number of the selected menu item. MATLAB remains in a waiting state while executing the MENU function until you have made your choice or the dialog window is closed. The menu dialog object exists only while the MENU function is running and is cleared from memory when the function ends. Thus, you cannot get a handle to a menu dialog window through the MENU function.
So you can not change the position of the MENU dialog box via a figure handle.

To work around this issue, you can modify menu.m. On line 238 in menu.m you set the figure window position. You can change the position as you prefer.
Please note that this change have not been tested and may affect the functionality of MATLAB. We are not able to guarantee that the modified menu.m MATLAB file will work with other built-in MATLAB functions.

Another option would be to use MATLAB’s GUI development environment GUIDE, to custom-design your own dialog box.

, la solution consiste donc à éditer la fonction menu.m et de modifier la position. D’ailleurs c’est bien marqué en commentaires dans la fonction menu.m que c’est le comportement désiré : Resize figure to place it in top left of screen

menu.m

Ma réponse fut : imaginez que ce soit le même comportement pour les figures modales comme questdlg , warndlg

et la dernière réponse du support:

We don’t really have an explanation to why the developers chose to put the MENU dialog box up in the left corner. We think that since the dialog could be of variable size, they decided to put it there.
We don’t think they had any ulterior motive when they placed it there.

C’est quand même fou qu’on soit obligé d’aller éditer une fonction MATLAB. Du coup moi si j’ai seulement 3 choix à proposer à l’utilisateur j’utilise à la place de menu une questdlg ;

>>choice = questdlg('Choose a color:','Menu','Red','Blue','Green','Red')

ce qui me donne la figure suivante :

questdlg

et elle au moins elle se met au milieu de l’écran !!

Laisser un commentaire