How to resize axes programmatically within a GUI built with uifigure and uigridlayout?
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi everyone,
I've been building a GUI based on a uifigure and the matlab.apps.AppBase tools. It's not built in App Designer, I do it programmatically. I use a uigridlayout to position my various items; it works quite well for most things, but I'm having trouble with uiaxes.
These uiaxes are located within the uigridlayout, but I need to make a slight size adjustment after they've been created. I just need to adjust the width, I know by how many pixels to adjust it. If I run my app by typing "app = appName();" in the command window, the app shows up, the uiaxes are not adjusted. I then issue the command in the command window: "app.myAxes.Position(3) = app.myAxes.Position(3) - boxWidth;", which does exactly what I need it to do.
However, adding that line of code in the code that builds the actual GUI does not work, no matter where I try to put it. I've set AutoResizeChildren of the uifigure to off, no luck. I've searched here, but nothing I found seems to work.
So how do I get my app to execute that particular line of code?
Cheers,
Christiane
댓글 수: 8
dpb
2024년 9월 12일
Indeed, there are probably significant differences in your code and an appdesigner-created one...
classdef myGUI < matlab.apps.AppBase
properties
fGUI;
axesGTextes;
axesDTextes;
boxWidth;
backgroundcolor;
end
methods
function app = myGUI()
The appdesigner mini app I posted looks like
lassdef testResizeUIAxes_exported < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
pos=app.UIAxes.Position;
pos(3)=0.75*pos(3);
app.UIAxes.Position=pos;
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
...
I'm guessing if you follow that template, then it will work as expected. In particular, the public properties and way they'r defined I suspect is where the problems lie -- and, a callback function is always expected to have the argument list of (app,event) which you're missing...
답변 (1개)
dpb
2024년 9월 12일
편집: dpb
2024년 9월 13일
Here's a start; I needed a break from other issues of the day so I began to reorganize in line with the appdesigner layout, but it didn't seem to make any real difference, somewhat to my surprise.
However, since it worked to reduce the size of an UIAxes in a figure; I'm thinking it must have something to do with it being in a grid layout and somehow what that does/displays. --- Oh, one other thought...well, that didn't work, either. I thought maybe if one deleted the axes and then recreated it with the new size, but no; it used the new size but was still rendered the same as before. I'm pretty sure this must have something to do with how grids work but I've never used one so know absolutely nothing about their intricacies.
But, here's a file rearranged to be more in line with appdesigner structure; unfortunately, it didn't seem to make any difference in the symtpoms.
댓글 수: 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!