Borrar filtros
Borrar filtros

Calculate the size needed for a uicontrol

3 visualizaciones (últimos 30 días)
Arthur
Arthur el 23 de Jun. de 2011
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Jun. de 2011
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 comentario
Jan
Jan el 27 de Jun. de 2011
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by