uibutton positioning when resize uifigure
21 次查看(过去 30 天)
显示 更早的评论
If I create a simple popup window like this:
h = uifigure; h.Position = [0 0 600 400]; centerfig(h)
uiLabel = uilabel(h,'Position',[30 360 540 30],'Text',{'Blah blah ...'});
uiOK = uibutton(h,'Position',[510 30 60 20],'Text','OK');
uiCancel = uibutton(h,'Position',[400 30 90 20],'Text','Cancel');
uit = uitable(h,'Data',rand(10,4),'Position',[30 90 540 250]);
It looks fine. And if I maximise the figure then the table resizes nicely and the label retains its position relative to the figure left. But the OK and Cancel buttons behave differently to each other.
The Cancel button retains its position relative to the figure left, which is what I expected, while the OK button retains its position relative to the figure right leaving a big gap in-between. The OK button behaviour might be desirable (and if they both did this it would save me having to do a resize function!), but I don't understand why the two buttons behave differently. Can someone explain?
2 个评论
Rik
2021-8-20
You could consider setting the Units property to Normalized. That way it will take up a fraction of your window, regardless of window size.
采纳的回答
Himanshu Jain
2021-8-23
As I understand, you have tried to align the 'OK' button with the right side of the UITable, so while resizing, matlab tries to hold that alignment.
When you maximize the figure window, the size of the table adjusts itself which is as expected and as the button is aligned with the right part of the table, the 'OK' button is shifted towards right.
If we talk about the 'Cancel' button, it is not aligned with any other component in the figure so it retains it's Position property even after maximizing the window.
To check the above statement, you can try to change the Position of the 'OK' button so that it does not align with the table. For example, you can execute the below code and try maximizing the window.
h = uifigure; h.Position = [0 0 600 400]; centerfig(h)
uiLabel = uilabel(h,'Position',[30 360 540 30],'Text',{'Blah blah ...'});
uiOK = uibutton(h,'Position',[510 30 50 20],'Text','OK');
uiCancel = uibutton(h,'Position',[400 30 90 20],'Text','Cancel');
uit = uitable(h,'Data',rand(10,4),'Position',[30 90 540 250]);
You will notice that now both the buttons retain their Position property even after maximizing the window.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!