Effacer les filtres
Effacer les filtres

Display default value in the edit box in MATLAB GUI

31 vues (au cours des 30 derniers jours)
Pankaja Tanjore
Pankaja Tanjore le 25 Juil 2015
Modifié(e) : Shameer Parmar le 14 Juin 2016
Hello,
I have a MATLAB GUI which contains the edit box.The value to this edit box is entered by the user . If the value is not entered by the user the default value has to be displayed or the previously set value has to be displayed in the edit box. Let me know how to set the default value to the edit box and display it if no value is entered , also how to store the value that is set . Previously set value has to be accessed and displayed if new value is not entered by the user.
It would be grateful if you let me know how this is done.
Looking forward to hear from you at the earliest.
Thanks
Pankaja

Réponses (2)

Walter Roberson
Walter Roberson le 25 Juil 2015
Initialization
handles.prev_value = TheDefaultValue;
set(handles.edit_box1, 'String', handles.prev_value);
and callback
function edit_box1_callback(hObject, event, handles)
new_value = strtrim(get(hObject, 'String'));
if isempty(new_value)
new_value = handles.prev_value;
end
set(hObject, 'String', new_value);
handles.prev_value = new_value;
guidata(hObject, handles);
end
  2 commentaires
Evan Bates
Evan Bates le 30 Avr 2016
where do you put the initialization?
Walter Roberson
Walter Roberson le 30 Avr 2016
You could put it in the Create function for edit_box1

Connectez-vous pour commenter.


Shameer Parmar
Shameer Parmar le 14 Juin 2016
Hello Pankaja,
You can do this, by creating new function in your code file (i.e. in .m file of your GUI).
1. Simply create new function at the end of your actual code as shown below:
function default(hObject, handles)
set(handles.edit1, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.edit2, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.edit3, 'string', 'WhateverYouWant_But_InStringFormat');
.
.
.
set(handles.edit100, 'string', 'WhateverYouWant_But_InStringFormat');
guidata(hObject, handles);
end
2. Call this function in the Opening function of your GUI as follows:
function xxxxxx_OpeningFcn(hObject, eventdata, handles, varargin)
% lines of code
.
.
default(hObject, handles);
.
.
guidata(hObject, handles);
end
You can call function "default()" wherever you want, in callback of any button/field of your GUI to make the text value default, as per your requirement.
Try for this and let me know if you face any issue

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by