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.
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.