Clear Filters
Clear Filters

How to create an uicontrol with selectable but non-editable text.

7 views (last 30 days)
I want to allow user copy a text (or it's part) into clipboard in usual manner (selecting by mouse and pressing Ctrl-C). How to make it? A 'text' style uicontrol doesn't permit selection. Оn the other hand, an 'edit' style permits selection and copying to clipbord but also allows editing what is not desirable.

Answers (2)

bbb_bbb
bbb_bbb on 25 Apr 2018
Edited: bbb_bbb on 25 Apr 2018
found "simple" solution:
javatxt = findjobj(editui);
javatxt.Editable=0;
where editui - an 'edit' style uicontrol,
findjobj - a function that Find java objects contained within a specified java container or Matlab GUI handle

Walter Roberson
Walter Roberson on 25 Apr 2018
Hack the Java objects underlying the uicontrol.
But first experiment with setting the uicontrol enable property to 'disable'. The result is a uicontrol that can still scroll but not be edited. I do not recall whether it is selectable.
  2 Comments
Dennis
Dennis on 25 Apr 2018

If it is okay to copy the entire text you could create a ButtonDownFcn that copies the string to clipboard.

function copytxt (hobj,~)
      mystring=get(hObj,'String'); 
      clipboard('copy',mystring)
end

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps 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!