Drop Down Menu Width

8 次查看(过去 30 天)
Bruno
Bruno 2013-4-21
编辑: Toby 2013-11-27
The width of the dropdown menus in Matlab GUIs appear to me to be fixed to their designated width. Is there a way to have the width of the drop down portion autosize to display the entire text of all selectable items without impacting the width of the item within the GUI window? See attached image for clarification.
Note: image currently under Mathworks review. Will be uploaded shortly.

回答(2 个)

Walter Roberson
Walter Roberson 2013-4-21
There is no way to do that, unless it is at the Java level.
What I used to do is calculate the required maximum width, based on the menu contents, and size according to that. That left blank space if the currently chosen menu item was not the widest item, but that is not necessarily a bad thing as users get disconcerted if the controls resize every time you choose a new item. For example, should items (such as other controls) further to the right be shifted left when the user selects a shorter menu item ?
  7 个评论
Bruno
Bruno 2013-4-22
Walter, I created a popup uicontrol item in code and it appears to autosize as you stated it would. Apparently the style of the popups created in GUIDE are "popupmenu" and not "popup". I tried to change the style with set, but it wouldn't allow me which is understandable.
Does anyone know how to change the "popupmenu" created with GUIDE into a "popup"?
Thanks, B
Toby
Toby 2013-11-27
编辑:Toby 2013-11-27
Matlab R2011b doesn't seem to differentiate between uicontrol Style 'popup' and 'popupmenu'. Also, I don't seem to be able to set a preference via the 'setConstrainPopupWidth' method of the underlying com.mathworks.hg.peer.ComboboxPeer$MLComboBox object. It defaults to 'off'; but with any attempt to change it, it remains set as 'off'. Though it looks like an unconstrained width used to be the 'default' feature (see Yair's book - Undocumented Secrets of MATLAB - Java Programming) But just as was the case for Bruno, the width of any dropdown menus in Matlab GUIs appear to me to be fixed to their designated width (as set by the popup uicontrol). Don't know if this is a result of the underlying class changing from a MJComboBox to MLComboBox? Seems like this should be a fairly straight-forward attribute to set though... Anybody know if this is definitely a version issue, or have any further ideas for a work-around?

请先登录,再进行评论。


Jan
Jan 2013-4-22
I have emulated a drop-down menu with a very small button and a UICONTEXTMENU, which is made visible in the button's callback. This works fluently, but the code is much less attractive than a uicontrol('Style', 'popup').

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by