How to arrange input fields straight below each other using inputsdlg?

9 ビュー (過去 30 日間)
Brezelbayer
Brezelbayer 2023 年 1 月 12 日
コメント済み: Brezelbayer 2023 年 1 月 12 日
I'm using the Matlab Add-On "inputsdlg: Enhanced Dialog Box" to catch information of participants. The dialog box works fine but looks messy, because the input fields are not arraged straight below each other since the promptheadlines have different lenghts.
So, what can I do that all the input fields start at the same width position of my dialog box window?
Using the regular "inputdlg" is not an option because I have a dropdown field in the dialog box.
Code:
% Add-On "inputsdlg" must be installed, otherwise code wont run!
name = 'Participantdata'; % Titel
prompt = {'ParticipantID';'FirstName';'LastName';'Age';'Sex'}; % Collected Data
formats = struct('type', {}, 'style', {}, 'items', {}, 'format', {}, 'limits', {}, 'size', {});
formats(1,1).type = 'edit';
formats(1,1).format = 'integer';
formats(1,1).limits = [0 1000];
formats(1,1).size = [200 20];
formats(2,1).type = 'edit';
formats(2,1).style = 'edit';
formats(2,1).format = 'text';
formats(2,1).size = [200 20];
formats(3,1).type = 'edit';
formats(3,1).style = 'edit';
formats(3,1).format = 'text';
formats(3,1).size = [200 20];
formats(4,1).type = 'edit';
formats(4,1).format = 'integer';
formats(4,1).limits = [1 150];
formats(4,1).size = [200 20];
formats(5,1).type = 'list';
formats(5,1).style = 'popupmenu';
formats(5,1).items = {'m','f'};
formats(5,1).size = [200 20];
defaultanswers = {0, 'NaN', 'Nan', 1, 1};
[answer, canceled] = inputsdlg(prompt, name, formats, defaultanswers);
Output:

採用された回答

Bora Eryilmaz
Bora Eryilmaz 2023 年 1 月 12 日
You won't get perfect alignment, but you can pad the prompt strings with empty spaces:
prompt = {...
'ParticipantID'; ...
'FirstName '; ...
'LastName '; ...
'Age '; ...
'Sex '}; % Collected Data
  1 件のコメント
Brezelbayer
Brezelbayer 2023 年 1 月 12 日
Thanks! Well, I guess for a perfect alignment it's better to create an app with a GUI than using inputsdgl.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDisplay and Presentation についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by