uibutton positioning when resize uifigure
29 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Justin
am 20 Aug. 2021
Kommentiert: Justin
am 23 Aug. 2021
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 Kommentare
Rik
am 20 Aug. 2021
You could consider setting the Units property to Normalized. That way it will take up a fraction of your window, regardless of window size.
Akzeptierte Antwort
Himanshu Jain
am 23 Aug. 2021
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!