为MATLAB按钮设置uibutton属性

时间:2013-06-19 19:27:20

标签: matlab button user-interface colors background

我正试图在程序忙于计算时将gui按钮的背景颜色设置为不同的颜色。如果我只是在单击按钮时将颜色设置为更改,则会更改;但是,如果我在实际计算之后添加另一行代码以将颜色更改回默认值,则颜色永远不会在第一次更改。

function FitData_button_Callback(hObject, ~, handles) %#ok<DEFNU>

set(handles.FitData_button,'BackgroundColor',[0 204 0]./255,'String','Fitting Data');

% do some computation that takes time here...

% this line causes the first instance of 'set' not to work
set(handles.FitData_button,'BackgroundColor',[237 237 237]./255,'String','Fit Data'); 

如果我第二次更改属性我调用'set',它会从默认值更改为第二次指定的值(并且在长计算完成后执行此操作)。但是,永远不会分配第一组属性。 因此,似乎我只允许一次设置BackgroundColor和String属性,这没有任何意义。

是什么给出的? 感谢

1 个答案:

答案 0 :(得分:3)

简短的回答是提出一个&#34; drawow&#34;在计算过程中。 Yair Altman在他的博客中最好地说明了答案(顺便说一句,这很棒) - http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/