Checkboxes disappear when a new one created (matlab 2007b)

조회 수: 2 (최근 30일)
Ilya Valmianski
Ilya Valmianski 2011년 3월 2일
Hello,
I have a button group with handle handles.dataSelect and I'm trying to add some texts and checkboxes to that group based on information contained in handles.dataStruct. I would expect the output to be something like
Channel Select
[] Channel 1
[] Channel 2
etc...
Temperature Select
[] T = 20 K
[] T = 40 K
etc...
However, what I see instead is
Channel Select
... lots of space ...
[] Last channel
Temperature Select
... lots of space ...
[] Last temperature
I checked and the button group does have all of the checkboxes as children and all children ARE in fact set to be visible and enabled.
However, I don't see any but the last channel and the last temperature. When I debugged, with every for loop iteration the previous checkbox disappeared from view while the new checkbox was added...
It seems like some simple mistake on my part, but I can't quite figure out what exactly I did wrong. Any help would be appreciated, the exact code I used is below.
Thank you,
Ilya
function createView( handles )
chPos=0.75;
handles.hText1=uicontrol(handles.dataSelect,'Style','text',...
'Tag','ChSelectText','String','Channel Select','Units','normalized',...
'HorizontalAlignment','left','Position',[0.1, chPos, 0.6, .2]);
for j=1:length(handles.dataStruct.channels),
handles.hChannelBox(j)=uicontrol(handles.dataSelect,...
'Style','checkbox','Tag',['Ch' num2str(j) 'box'],'String',...
['Channel ' num2str(handles.dataStruct.channels(j))],...
'Units','normalized','HorizontalAlignment','left',...
'Position',[0.1, chPos-j*0.06, 0.6, .2]);
end
tempPos=chPos-length(handles.dataStruct.channels)*0.06-0.2;
handles.hText2=uicontrol(handles.dataSelect,'Style','text',...
'Tag','TempSelectText','String','Temperature Select',...
'Units','normalized','HorizontalAlignment','left','Position',...
[0.1, tempPos, 0.6, .2]);
for j=1:length(handles.dataStruct.temps),
handles.hTempBox(j)=uicontrol(handles.dataSelect,...
'Style','checkbox','Tag',['Temp' num2str(j) 'box'],'String',...
['T = ' num2str(handles.dataStruct.temps(j)) ' K'],...
'Units','normalized','HorizontalAlignment','left',...
'Position',[0.1, tempPos-j*0.06, 0.6, .2]);
end
guidata(handles.dataSelect, handles);
end

채택된 답변

Matt Fig
Matt Fig 2011년 3월 2일
You are overlapping each with the next. (This is why I prefer to work in pixels by the way.)
For starters, change:
[0.1, chPos-j*0.06, 0.6, .2]
to
[0.1, chPos-j*0.06, 0.6, .1]
in the first FOR loop. You will have to play around with the numbers to get them correct and look like what you want.
  댓글 수: 1
Ilya Valmianski
Ilya Valmianski 2011년 3월 2일
You sir, are quite right! Didn't know it would disable the view of one of them if I did it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by