0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MATLAB listdlgのフォントを変える

0
Posted at

listdlgは古いJavaベースのGUIのシステムフォントを使用しているため、uialert や uiconfirm などのモダンなデザインではない。
また、listdlgにフォント(FontNameやFontSize)を直接変更するプロパティは用意されていない。
対応として、uicomponent(リストボックス)を埋め込んだ uiconfirm を使用する

[サンプルコード]

function selectedValue = myModernListDlg(listItems, titleText, promptText)
    % 1. ベースとなる非表示のUIフィギュア(ウィンドウ)を作成
    fig = uifigure('Name', titleText, 'Visible', 'off');
    % ウィンドウの中央に配置するための位置計算
    fig.Position(3:4) = [300 250]; 
    movegui(fig, 'center');

    % 2. グリッドレイアウトでプロンプトとリストボックスを配置
    gl = uigridlayout(fig, [2, 1]);
    gl.RowHeight = {'wrap', '1x'};

    % プロンプト(説明文)のラベル
    uilabel(gl, 'Text', promptText, 'FontWeight', 'bold');

    % リストボックス(これがuialertと同じモダンフォントになります)
    lb = uilistbox(gl, 'Items', listItems);

    % 3. フィギュアを表示させてから、uiconfirmを呼び出す
    fig.Visible = 'on';
    selection = uiconfirm(fig, '項目を選択してください。', titleText, ...
                          'Options', {'OK', 'キャンセル'}, 'DefaultOption', 'OK');

    % 4. ユーザーの選択結果に応じて戻り値を設定
    if strcmp(selection, 'OK')
        selectedValue = lb.Value; % 選択された文字列
    else
        selectedValue = []; % キャンセル時
    end

    % 使い終わったらフィギュアを閉じる
    close(fig);
end

[使い方]

items = {'オプション A', 'オプション B', 'オプション C'};
chosen = myModernListDlg(items, '設定選択', 'どれか一つ選んでください:');
disp(['選択されたのは: ', chosen]);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?