1

Matlab の App Designer (2019b) を使用して GUI を作成しています。の優れた機能の 1 つは、NumericEditField値の制限を定義して、ユーザーが目的の範囲外の値を入力できないようにすることです。たとえば、次の例では、編集フィールドの値が -100 ~ 100 に制限されます。

app.numericEditField1.Limits = [-100 100];

GUIにもuitableオブジェクトがあります。編集フィールドのように、データ テーブルのセルに値の制限を設定することはできますか? 明らかに同等のプロパティは見当たりませんでした。CellEditCallback回避策として、値が変更されるたびに値を手動で確認するように編集することをお勧めします。

以下は、制限付きの値編集フィールドと通常のuitable. テーブルの特定の列にも値制限を設定したいと思います。

サンプルコード

classdef sampleLimitedValApp < matlab.apps.AppBase

% Properties that correspond to app components
properties (Access = public)
    UIFigure                        matlab.ui.Figure
    LimitedEditValueEditFieldLabel  matlab.ui.control.Label
    LimitedEditValueEditField       matlab.ui.control.NumericEditField
    UITable                         matlab.ui.control.Table
end

% Callbacks that handle component events
methods (Access = private)

    % Code that executes after component creation
    function startupFcn(app)
        app.UITable.Data = zeros(3,4);
    end
end

% Component initialization
methods (Access = private)

    % Create UIFigure and components
    function createComponents(app)

        % Create UIFigure and hide until all components are created
        app.UIFigure = uifigure('Visible', 'off');
        app.UIFigure.Position = [100 100 383 331];
        app.UIFigure.Name = 'UI Figure';

        % Create LimitedEditValueEditFieldLabel
        app.LimitedEditValueEditFieldLabel = uilabel(app.UIFigure);
        app.LimitedEditValueEditFieldLabel.HorizontalAlignment = 'right';
        app.LimitedEditValueEditFieldLabel.Position = [31 280 101 22];
        app.LimitedEditValueEditFieldLabel.Text = 'Limited Edit Value';

        % Create LimitedEditValueEditField
        app.LimitedEditValueEditField = uieditfield(app.UIFigure, 'numeric');
        app.LimitedEditValueEditField.Limits = [-100 100];
        app.LimitedEditValueEditField.Position = [147 280 100 22];

        % Create UITable
        app.UITable = uitable(app.UIFigure);
        app.UITable.ColumnName = {'Column 1'; 'Column 2'; 'Column 3'; 'Column 4'};
        app.UITable.RowName = {''};
        app.UITable.ColumnEditable = true;
        app.UITable.Position = [31 67 302 185];

        % Show the figure after all components are created
        app.UIFigure.Visible = 'on';
    end
end

% App creation and deletion
methods (Access = public)

    % Construct app
    function app = sampleLimitedValApp

        % Create UIFigure and components
        createComponents(app)

        % Register the app with App Designer
        registerApp(app, app.UIFigure)

        % Execute the startup function
        runStartupFcn(app, @startupFcn)

        if nargout == 0
            clear app
        end
    end

    % Code that executes before app deletion
    function delete(app)

        % Delete UIFigure when app is deleted
        delete(app.UIFigure)
    end
end
end
4

1 に答える 1