Scrollable text box for GUI with selectable/editable text
30 views (last 30 days)
Show older comments
John on 23 Jan 2020
Commented: John on 28 Jan 2020
I am trying to create a scrollable GUI text box with selectable text. It seems that this can't be done using the standard Matlab uicontrols since text selection is disabled when scrolling is enabled. From other answers in this forum, I understand this has to be done in Java. I have had partial success using Yair Altman's excellent utilities "uicomponent" and "attachScrollPanelTo". By attaching a ScrollPanel to a JTextArea (demo code below), I nearly get what I need, but unfortunately I am only able to scroll through a limited range of the text. Is it possible to adjust the scroll limits so that the entire text can be seen? Any advice would be greatly appreciated!
%create a random string
s = 'a':'z';
textString = ['start ' s(randi(26,1,10000)) ' end'];
hFig = figure(1);
hFig.OuterPosition=[0 0 1 1];
hPan = uipanel('FontSize',12,...
'Position',[0 0 1 1]);
pos = getpixelposition(hPan);
jTA = uicomponent('Parent',hPan,'style','javax.swing.jtextarea','tag','myObj',...
'BackgroundColor',[0.6 0.6 0.6],'Opaque',0,'LineWrap',1);
jTA.Font = java.awt.Font('Helvetica', java.awt.Font.PLAIN, 22); % font name, style, size
jTA.Foreground = java.awt.Color(1,1,1);
%attach scroll panel
hSP = attachScrollPanelTo(jTA);
%resize figure to reveal vertical scrollbar
hFig.OuterPosition=[0 0 1 0.5];
Yair Altman on 24 Jan 2020
Your script generates a GUI that looks perfectly ok to me (fully scrollable & selectable) on my Win10, in both 18b and 20a.
You set the figure's OuterPosition to [0,0,1,.5], so the botttom part of the figure (with the horizontal scrollbar) is hidden beneath the Windows taskbar. But if you set the OuterPosition to be a bit higher (or if you simply drag the figure upward), you'll see the scrollbar.
In other words, I see nothing wrong.
More Answers (0)
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!