How to compose a formula in a GUI
6 views (last 30 days)
Show older comments
Hello,
In my GUI a have a list box (lstVariables) with variable names and an edit box (txtEditor) where I want to write a formula. When I click in the list box, I want to add the selected variable in the edit box. The difficulty is that I want to add it on the place where the cursor was.
Example : I have in the edit box the text : "var1 + var2 + var3", I select in the edit box "var2" (so it's highlighted) and than I click in the listbox on var4. The result should be : "var1 + var4 + var3". How can I find which part of the edit box is selected ?
My Example code up to now :
function lstVariables_Callback(hObject, eventdata, handles)
varnames = cellstr(get(hObject,'String'))
varname = varnames{get(hObject,'Value')}
set(handles.txtEditor,'String',varname);
All help is appreciated.
Best regards,
Luc.
0 Comments
Accepted Answer
Walter Roberson
on 2 May 2011
You will have to work at the Java level for this, in order to find out what was highlighted. I recommend that you look at Yair Altman's site, http://undocumentedmatlab.com
0 Comments
More Answers (1)
Luc
on 2 May 2011
1 Comment
Walter Roberson
on 2 May 2011
No text would have been selected at ButtonDownFcn time; the selection is made at ButtonUpFcn time.
See Also
Categories
Find more on Environment and Settings 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!