listdlg obscures longer prompts
14 次查看(过去 30 天)
显示 更早的评论
I'm using a listdlg to get information from users, but the prompt for my dialog is too long to fit on one line. Unfortunately the second line is obscured by the top of the list box. Is there a way to fix this other than making my dialog window unnecessarily wide?
1 个评论
Image Analyst
2013-4-21
I'd send that in as a bug, or at the very least, a request for enhancement. I mean, you should be able to have more than one short line as a prompt!
采纳的回答
更多回答(2 个)
Jan
2013-4-21
Create a copy of LISTDLG in a user-defined folder and modify it accordingly: You need a modification of the 4th argument of the position in:
listsize = listsize - [0, 32];
listbox = uicontrol('style','listbox', ...
'position', [ffs+fus, ffs+uh+4*fus+(smode==2)*(fus+uh) listsize],...
A smart idea would to perform this dynamically depending on the extent of the prompt:
ext = get(prompt_text, 'Extent');
listsize = listsize - [0, ext(4) + 30];
Marcel
2022-11-7
编辑:Marcel
2022-11-7
Despite the issue being old and already having a answer, i wanted to post my solution as well. By using the following code, those empty {''} values are added automatically for every 32 characters in the string. I at least use this function myself so i can have an easier time calling it etc and since im working on my github repo for matlab hacks, this might be a good thing to post.
Tested in Matlab R2021a.
answer = msgList(["Live", "Statisch"], ...
"This is a lot of text it is amazing the char limit for one line seems" + ...
" to be 32 characters. its amazing to be able to work around it tho", ...
"An interesting title");
function results = msgList(list, prompt, title)
lineBreaks = [];
counter = 1;
for i = 1:strlength(prompt)
if counter == 32
lineBreaks = [{''}, lineBreaks];
counter = 1;
end
counter = counter + 1;
end
[index,tf] = listdlg('PromptString',[{prompt}, lineBreaks], 'ListString',list, "SelectionMode", "single", "Name", title);
results = list{index};
end
1 个评论
Damien Watson
2024-1-4
Another optimisation could be to calculate lineBreaks using:
numLineBreaks = floor(strlength(prompt) ./ 32);
% For strings
lineBreaks = strings([numLineBreaks, 1]);
% Or for chars
lineBreaks = repmat({''}, [numLineBreaks, 1]);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!