Calculate the size needed for a uicontrol

3 次查看(过去 30 天)
I'm trying to calculate the actual size needed for uicontrols in a GUI so the GUI can resize itself appropriately. My problem is that the Extent property of a uicontrol is only the text area, and I can't find a way to determine the size of the surrounding control (such as the down arrow in a popup or the margin of an edit control). Is there a way to get the size of the decorations on a control?
I saw this related question, which looked like it ended with no solution as well.

采纳的回答

Walter Roberson
Walter Roberson 2011-6-23
There is no documented way to do this. I do not know if there is a way to figure things out at the Java level.
What I ended up having to do was use trial and error to measure the widths of the various forms of decoration. I then wrote my own hgrightsize() routines that figures out the class of graphics element (e.g., text() vs uipanel() vs uicontrol) and dispatches to the appropriate "right sizing" subroutine.
I cannot give you the code, but I can tell you the experimental values for uicontrols, in pixels:
checkbox: 15
edit box: decoration 21 if multiline, 0 for single line
listbox: 19
popup: 16
pushbutton: 0
radiobutton: 15
slider: meaningless to "rightsize" a slider
textbox: 0
togglebutton: 0
There are some complications when you are determining the size of the text area itself via Extent: in some cases you should only look at the first line of a multiline String, and in other cases you need to find the widest line of the multiline string; in some cases the height of your box is one line and in other cases it should be the height of all of the lines. Those factors are easier to determine than the number of pixels of margin to allow for decorations.
  1 个评论
Jan
Jan 2011-6-27
The dimensions of the sliders of a UILISTBOX depend on the display settings under Windows: Using a different scheme can modify the slider width also. Using the undocumented "get(H, 'PixelBounds')" does not helpe here, because it is equivalent to the usual "get(H, 'Position')" considering an extra margin of 6 pixels.

请先登录,再进行评论。

更多回答(0 个)

类别

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