How to "wrap text" on pushbutton string?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Epri Pratiwi
il 17 Ago 2020
Commentato: Andreas Nickel
il 16 Lug 2025
I have a long tittle for a file. When I tried to show the tittle on pushbutton, it become like this. I want the rest of tittle goes down or look like in "wrap text" mode (just like in Excel).

0 Commenti
Risposta accettata
Walter Roberson
il 17 Ago 2020
Modificato: Walter Roberson
il 17 Ago 2020
Create a figure. Create a uipanel within the figure. Create a uicontrol style text or edit with Max set greater than 1, with parent set to the uipanel. Set the Position property to the height and width you want the pushbutton to have, plus a magic number margin to take into account the outside and decoration of uicontrol style text. Make sure the uicontrol has the right font name and font size that you will be using.
Now wraptext() with the control and the text you want for the button. You will get out a cell array of character vectors that contains the split text.
Option 1:
Now set the string property of the uicontrol to the wrapped text cell array. Set the Position of the uipanel to just enclose the uicontrol. And then use saveas() or print() or exportgraphics() to capture a copy of the rendered text and write out to a file and imread the file, /Or capture() the uipanel into an array. With the array on hand either way, set the CData property of the pushbutton to have an image of the text
Option 2: take the cell array of character vectors and use insertText from the Computer Vision Toolbox to render the text into an array. Then set the CData property of the pushbutton to be the image of the wrapped text.
Afterwards, clean up.
You might have noticed here that:
A) you cannot just pass in an array size and text and ask to wrap it, or render it in wrapped form;
B) pushbuttons do not support multi-line labels, so you have to put in a picture of the text.
But never let it be said that I didn't tell you how to do the task. It is possible.
You might want to consider separating the label into a uicontrol style edit with Enable set to disable. When you do that, you will get scroll bars but the user will not be able to edit. Then put a button without a label.
2 Commenti
Andreas Nickel
il 16 Lug 2025
It’s still possible in MATLAB R2025a e.g.:
uicontrol('Style','pushbutton' ,'Units','normalized','Position',[0.005 0.005 0.1 0.09],'String', {'Line 1','Line 2'})
Più risposte (1)
Vladimir Sovkov
il 17 Ago 2020
Modificato: Vladimir Sovkov
il 17 Ago 2020
Use the cell array with entries containing text fragments to be shown in separate strings.
Vedere anche
Categorie
Scopri di più su Convert Image Type in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!