Is there a way to fit long text in a grid with ellipsis?

1 次查看(过去 30 天)
Here is an example of what I mean -
The above images are arranged in a Grid layout (using GUI Layout Toolbox), so each axes are in their own uicontainer, which means any text from one grid will be overlaid on top by the a subsequent grid, therefore hiding the text if it's beyond the boundary of its own grid. As you can see, the texts (.170) and (.txt) are partially hidden because of this.
To solve this problem, one would have to replace the extra text with ellipsis (...) to shorten the text and make it fit into the grid. An example is the Windows explorer, showing below, where the text (.170) is replaced with (.1...) as it is shorter in length.
Apparently, this requires the dertermination of the width (or length) of the actual text, which has a lot to do with the font size and font used. Unless it's monospaced font, using number of characters to determine the length is not enough. For example, 'iii' is much shorter than 'DDD' in width.
In MATLAB, although you can determine the width of the graphics text object, the extent of the box that encloses the text is a read-only property, therefore it's not possible to restrict the width of the text object (and MATLAB also has to know to put ellipsis when the text is restrained). A lengthy workaround would be to calculate the width of the text based on its font and font size, and if it's wider than the grid, you'll have to iteratively shortern its characters one by one and determine whether the shortened text would fit inside the grid, while adding ellipsis into the mix.
  2 个评论
Adam Danz
Adam Danz 2020-1-26
编辑:Adam Danz 2020-1-26
I don't have this toolbox so I can't play around with it but you could putting line breaks in to the text such as
s = ['Protein-DNA',newline,'complex.txt'];
% or
s = sprintf('Protein_DNA\ncomplex.txt');
I have no idea if the line break will be interpreted correctly or whether the 2nd line will be cut off.
Eddie
Eddie 2020-1-26
That won't work on very long file names, however.
A related problem, but in reverse, was asked in the following post before. In that post, the poster wanted to use multi-line instead of ellipsis (albeit that is on a checkbox uicontrol instead of a text axis object).

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by