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

조회 수: 3 (최근 30일)
Eddie
Eddie 2020년 1월 26일
댓글: Eddie 2020년 1월 26일
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에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by