ListBoxTop property not updating displayed listbox line

조회 수: 3 (최근 30일)
Matthew Lang
Matthew Lang 2012년 4월 16일
I've seen several other users in the past that had issues w/ listboxes & viewing the bottom-most data. Usually the answers include using the 'ListBoxTop' property, which should be the correct answer. But I don't find any code snippets that actually work (and I don't want to put my hands into the java guts w/ undocumented properties unless absolutely necessary). So, here's the gauntlet once and for all...why doesn't this code display the bottom line of the listbox?
function ListboxTester_01
fh = figure('MenuBar','none',...
'NumberTitle','off',...
'Position',[200 200 170 100],...
'Name','ListboxTester');
cwh = uicontrol(fh,...
'Style','edit',...
'Max',4,...
'Position',[10 40 150 50],...
'HorizontalAlignment','left',...
'SelectionHighlight','of',...
'HitTest','off');
uicontrol(fh,...
'Style','pushbutton',...
'String','test',...
'Position',[10 10 150 20],...
'Callback',@testbutton_callback);
ii=1;
function testbutton_callback(~,~)
inputstring = sprintf('Testing%d',ii);
cwhstring = get(cwh,'String');
newtext = cell(length(cwhstring)+1,1);
newtext(1:end-1) = cwhstring;
newtext(end) = {inputstring};
set(cwh,'String',newtext);
set(cwh,'ListBoxTop',numel(newtext),'Value',numel(newtext));
drawnow;
ii = ii+1;
end
end
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2012년 4월 16일
+1, well written question with all of the info we could ask for.

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

답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 4월 16일
Because it's an edit uicontrol and not a listbox uicontrol. Change line seven to:
'Style','listbox',...
and watch the magic!

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by