listdlg obscures longer prompts

18 visualizaciones (últimos 30 días)
Bruno
Bruno el 21 de Abr. de 2013
Comentada: Damien Watson el 4 de En. de 2024
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 comentario
Image Analyst
Image Analyst el 21 de Abr. de 2013
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!

Iniciar sesión para comentar.

Respuesta aceptada

Bruno
Bruno el 5 de Mayo de 2013
For anyone out there experiencing the same frustration as I was, the solution I've come up with is to enter the prompt string as a cellstr in which the first cell entry is the prompt, and subsequent empty strings {''} are padded onto the end. See below for example.
listdlg('PromptString','This is a long prompt string for the purposes of illustrating my point.','ListString',[{'blah'} {'blah'} {'blah'}])
listdlg('PromptString',[{'This is a long prompt string for the purposes of illustrating my point.'} {''}],'ListString',[{'blah'} {'blah'} {'blah'}])
  4 comentarios
JohnDylon
JohnDylon el 18 de En. de 2017
Add another {''} and problem is solved. See below:
listdlg('PromptString',[{'This is a long prompt string for the purposes of illustrating my point.'} {''} {''}],'ListString',[{'blah'} {'blah'} {'blah'}])
Sokratis Panagiotidis
Sokratis Panagiotidis el 2 de Abr. de 2022
Man your answers were a huge help, thanks a lot!

Iniciar sesión para comentar.

Más respuestas (2)

Jan
Jan el 21 de Abr. de 2013
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];
  2 comentarios
Bruno
Bruno el 22 de Abr. de 2013
Jan, I'm trying that and Matlab is complaining that the following functions are undefined. How do I resolve this?
warnfiguredialog
getnicedialoglocation
setdefaultbutton
Walter Roberson
Walter Roberson el 22 de Abr. de 2013

Iniciar sesión para comentar.


Marcel
Marcel el 7 de Nov. de 2022
Editada: Marcel el 7 de Nov. de 2022
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 comentario
Damien Watson
Damien Watson el 4 de En. de 2024
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]);

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by