How to "wrap text" on pushbutton string?

8 vues (au cours des 30 derniers jours)
Epri Pratiwi
Epri Pratiwi le 17 Août 2020
Commenté : Epri Pratiwi le 17 Août 2020
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).

Réponse acceptée

Walter Roberson
Walter Roberson le 17 Août 2020
Modifié(e) : Walter Roberson le 17 Août 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.
  1 commentaire
Epri Pratiwi
Epri Pratiwi le 17 Août 2020
Thanks for the info! I will try to use image for the pusbutton that contains the tittle.

Connectez-vous pour commenter.

Plus de réponses (1)

Vladimir Sovkov
Vladimir Sovkov le 17 Août 2020
Modifié(e) : Vladimir Sovkov le 17 Août 2020
Use the cell array with entries containing text fragments to be shown in separate strings.
  1 commentaire
Epri Pratiwi
Epri Pratiwi le 17 Août 2020
I don't think if it's possible. Making a multiline text display is not possible on pushbuttons.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by