App Designer uitextarea control gives position values not in pixels when window is maximised?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Here is the output. Can this be translated into pixels or any alternatives?
ans =
1.0e+03 *
1.2728 0.7737 0.6092 0.1143
Accepted Answer
Ajay Kumar
on 13 Nov 2019
Edited: Ajay Kumar
on 14 Nov 2019
When I do this:
fig = uifigure;
txa = uitextarea(fig);
txa.position
I get the Output as 100 100 150 60 which are pixels.
7 Comments
That is true but there is some weirdness in MATLAB that it is often there may be other factors that effect it. So, I just tested the code below which does the job, both in normal and maximised. However, the UI for the app I am working is more and there are more controls in that MATLAB may have to consider when doing the "Auto" anchoring of controls, tho the other controls give pixel values which is wierd that it may be only the UITextarea.
The problem is unreproducible, check the zip also tested it in App Designer.
fig = uifigure;
txa = uitextarea(fig, 'position', [10 100 250 100]);
b = uibutton(fig)
b.ButtonPushedFcn = @(src, event)disp(fig.Children(2).Position)
Ajay Kumar
on 14 Nov 2019
Edited: Ajay Kumar
on 14 Nov 2019

The app is working perfectly fine with me, as you can see when I click Show Positions button, I can see the position of text area(in PIXELS) in Positions text field.
Also, it works when I maximise the window. Replace the Show Positions callback with
app.PositionsEditField.Value = num2str(fix(app.TextArea.Position));
Also, If you want the components position to be fixed even if window is maximised, you can set the AutoResizeChildren to off
for example
fig = uifigure;
fig.AutoResizeChildren = 'off';
txa = uitextarea(fig, 'position', [10 100 250 100]);
b = uibutton(fig)
b.ButtonPushedFcn = @(src, event)disp(fig.Children(2).Position)
Bereketab Gulai
on 14 Nov 2019
Edited: Bereketab Gulai
on 14 Nov 2019
Thanks for your time.
Here is what fix() produced for the numbers that were given by the Position property. Which is does not seem useful.
>> c = [1.2728 0.7737 0.6092 0.1143]
c =
1.2728 0.7737 0.6092 0.1143
>> fix(c)
ans =
1 0 0 0
I am looking to keep it so that it resizes the children, but it should not also change the unit I suppose for specific ones. I have tried applying the unit measurement property to pixels just before calling the Position property of uitextarea.
Bereketab Gulai
on 14 Nov 2019
Edited: Bereketab Gulai
on 14 Nov 2019
Apparently the: fix()
fix(app.TextArea.Position)
Did the "fix" so it is now shows pixel values correctly. This problem I supppose is related to the where number editField would show numbers in that representation due too long and this can be resolve by changing "ValueDisplayFormat" property to integer.
FYI:
I came to this conclusion after checking the internal value of the control, using mlapptools, which was intact, only at the higher level was being modified.
I think you are missing out something in c
In the comment above you have considered c as
c = [1.2728 0.7737 0.6092 0.1143]
you are missing to multiply *1.0e+03
which indicates
[1272.8 773.7 609.2 114.3]
which are pixels.
That is correct, they can be restored to correct unit.
Thank you
More Answers (0)
Categories
Find more on Develop Apps Programmatically in Help Center and File Exchange
Tags
See Also
on 13 Nov 2019
on 14 Nov 2019
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)