MATLAB Answers

Naz

Message window in GUI (MatLab)

Asked by Naz
on 13 Oct 2011
Latest activity Commented on by Victor Hugo Souza on 29 Jan 2015

Hello. I am trying to create a text window in GUI that will be used to display messages/current activity of the program. It should be similar to the Command Window of matlab. That is, when I want to output some message, the message should appear in my text window of the GUI, not in the Command Window. Also, the text window will be used only for output, so no input will be preformed. I use the 'edittext' component as follows:

set(handles.edit1,'String','My message' );

however, next time when I want to output a new message, I want the old message to be present in the message box as well. That is, my message box should accumulate all the messages over time (or at least several most recent strings) just like Command Window or any console window does.

Thank you

  0 Comments

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 13 Oct 2011
 Accepted answer
oldmsgs = cellstr(get(handles.edit1,'String'));
set(handles.edit1,'String',[oldmsgs;{'My message'}] );

And be sure to set the edit box to 'Enable', 'disable'.

I thought I wrote about this topic just about a week ago, but I cannot seem to find that message.

Automatically position the scroll bar to any particular position in the edit list box requires resorting to the Java level.

  4 Comments

Walter Roberson
on 14 Oct 2011

To position the editbox scroll bar at the bottom, you need to head over to Undocumentedmatlab.com

Myself, I work a different way: I put a text box inside a uipanel, set the uipanel to clipping, add a scrollbar outside of the uipanel, and I have the scrollbar change the Position property of the text box to make it appear to scroll (when really it is being panned and the edges clipped by the uipanel boundaries.)

Naz
on 14 Oct 2011

I will try to do that

Victor Hugo Souza on 29 Jan 2015

I used a trick to overcome the fact that the scroll doesn't update when you add new text lines to the Edit Box. If you change the order of 'My message' and 'oldmsgs' the new messages will always appear on top of the edit text. Finally, if the user wants to go back to past messages he just need to scroll down the text.

oldmsgs = cellstr(get(handles.edit1,'String'));
set(handles.edit1,'String',[{'My message'};oldmsgs] );

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today