How to extend horizontally this inputdlg window?

4 次查看(过去 30 天)
Dear all,
I have this code for inputdlg window:
prompt = {'Nastavení výšky modelu:','Nastavení jemnosti sítě modelu:','Nastavení počtu elektrod:','Nastavení vzdálenosti mezi elektrodami:','Nastavení poloměru elektrod:','Nastavení tvaru elektrod:','Nastavení jemnosti sítě elektrod:','Nastavení normy - doplnit:'};
dlg_title = 'Nastavení parametrů modelu';
num_lines = 1;
defaultans = {'1','0.8','16','1','0.05','0','0.4','256'};
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
I would like to extend horizontally this window, because there isn´t display title of window. Can you advise me?

采纳的回答

Star Strider
Star Strider 2017-3-11
All you need to do is to define ‘num_lines’ to be a matrix. Here, I defined them as all being 75 characters wide:
prompt = {'Nastavení výšky modelu:','Nastavení jemnosti sítě modelu:','Nastavení počtu elektrod:','Nastavení vzdálenosti mezi elektrodami:','Nastavení poloměru elektrod:','Nastavení tvaru elektrod:','Nastavení jemnosti sítě elektrod:','Nastavení normy - doplnit:'};
dlg_title = 'Nastavení parametrů modelu';
defaultans = {'1','0.8','16','1','0.05','0','0.4','256'};
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*75];
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
  5 个评论
Star Strider
Star Strider 2017-3-11
I suppose you could somehow recover the title font size, estimate the length (in millimetres or pixels or whatever) necessary to show the entire title, then translate that to the necessary length requirement for ‘num_lines’ as the number of characters in the input window length, and then set that.
It seems to me to be easier to simply update the documentation to include that option as a more obvious solution rather than ‘camouflaging’ it. We’re experienced with MATLAB, and if it takes us time to find it and experiment with it, those less experienced will quite likely never find it.
dpb
dpb 2017-3-11
I agree at a minimum the doc ought to be improved; I don't do gui's but what few times have used the UIdialogs it has often seemed they've been so neutered from what the underlying OS parameters are that one almost always ends up with some issue if it's more than just the simplest of uses.

请先登录,再进行评论。

更多回答(2 个)

dpb
dpb 2017-3-11
编辑:dpb 2017-3-11
Don't see a way programmatically, TMW didn't expose the rest of the control properties thru the provided interface, unfortunately.
...[Previous use of longer prompt to fudge field width elided for brevity--dpb]...
Just point out one way to implement the TMW-suggestion linked to by IA and as fixed-width by SS above...
N=max(length(dlg_title),max(cellfun(@length,prompt)))+1; % get max length + offset
numel=repmat([1 N],length(prompt),1); % build numel array from inputs
Empirically the '+1' above was just enough; as observed in above comment this is an empirical adjustment, unfortunately.
What a kludge, though! :( This should be cited and an enhancement request submitted to TMW www.mathworks.com official support.

Image Analyst
Image Analyst 2017-3-11
  1 个评论
dpb
dpb 2017-3-11
编辑:dpb 2017-3-11
Ah...shoulda' read the doc more carefully, the TMW-supplied answer at the above link uses the array form for the num_lines parameter where the first column is number of lines for each prompt while the second is the width of the column. So, add the characters of the difference between length of title and prompt plus some for the field width and the prompt boxes will be wide-enough.
Much cleaner than the above forcing a long-enough title for a prompt, but similar "trick" to force the sizing algorithm to work.
Be much better if TMW would do this internally, though; why wouldn't one if given the task to implement the UI? Or perhaps there was no internal test that uncovered the case of title display length > prompt length so it all seemed to work fine in internal test suite?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by