Clear Filters
Clear Filters

Changing color of Button

7 views (last 30 days)
Teresa
Teresa on 2 Aug 2011
With some help i've created a variable amount of buttons in my gui:
for n=1:s
handles.b{n}=uicontrol('Style','PushButton','Units','pixels', 'Position',[125-breiteQuadrat/2-5+breiteQuadrat*n 45 10 10],'Visible','on');
end
Now i want to colour the button when it is selected and when you click twice it has the start-colour. here i call the callback function:
for n=1:s
set(handles.b{n},'Callback',@(obj,event)varBButton_Callback(n,hObject,eventdata,handles));
end
for the callback i implemented a new function:
function varBButton_Callback(n,hObject, eventdata, handles)
if get(handles.b{n},'Value')==get(handles.b{n},'Max')
set(handles.b{n},'BackgroundColor',[1 0 0],'Value','Min');
set(handles.tauschButton,'enable','on');
set(handles.deaktivierenButton,'enable','on');
else
set(handles.b{n},'BackgroundColor',[1 1 1],'Value','Max');
end
guidata(hObject, handles);
the change of the value doesn't work but i can't find my mistake.
and after that i want that it is possible to remove or change the position of the selected button. maybe someone has an idea how to realize that problem Thank you

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 2 Aug 2011
Probably this line is the problem:
set(handles.b{n},'BackgroundColor',[1 0 0],'Value','Min');
The 'Value' property can't be a string 'Min'. You probably mean to be:
set(handles.b{n},'BackgroundColor',[1 0 0],'Value',get(handles.b{n},'Min'))
Same problem for the other line.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!