Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 防止在GUI文本中换行_Matlab_Text_Matlab Guide_Word Wrap - Fatal编程技术网

Matlab 防止在GUI文本中换行

Matlab 防止在GUI文本中换行,matlab,text,matlab-guide,word-wrap,Matlab,Text,Matlab Guide,Word Wrap,我有一个MatlabGUI,允许用户加载配置文件。然后,我希望文件名显示在静态文本字段中。我的问题是,字符串对于我的文本字段来说太长,并且会缠绕。我希望文本在不换行的情况下尽可能多地显示字符串,并对字符串的结尾进行优先级排序 例如,如果我有一个文件名'C:\folders\more\folders\thismylongfilename.txt',我当前看到 C:\folders\more\folders\thisism ylongfilename.txt 如果我使用

我有一个MatlabGUI,允许用户加载配置文件。然后,我希望文件名显示在静态文本字段中。我的问题是,字符串对于我的文本字段来说太长,并且会缠绕。我希望文本在不换行的情况下尽可能多地显示字符串,并对字符串的结尾进行优先级排序

例如,如果我有一个文件名
'C:\folders\more\folders\thismylongfilename.txt'
,我当前看到

C:\folders\more\folders\thisism
              ylongfilename.txt
如果我使用编辑文本而不是静态文本,我会看到
C:\folders\more\folders\thisism

我希望我的文本字段显示
olders\thismylongfilename.txt
,或者可能显示
…ers\thismylongfilename.txt
。缺少的部分可以“显示”但在可见框之外,或者在显示之前可以删除。我只需要知道要删除多少字符串


如何在固定宽度的文本框中正确显示长字符串?

实现这一点的一种方法是读取文本框的长度,并在显示之前缩短字符串

myString = 'path/to/file/file.txt';

set(handles.textbox,'Units', 'Characters'); %set units to characters for convenience
pos = get(handles.textbox,'Position'); %get the position info
maxLength = floor(pos(3)); %extract the length of the box 
if length(myString) > maxLength % cut beginning if string is too long 
    newStart = length(myString) - maxLength + 1;
    displayString = myString(newStart:end);
else
    displayString = myString;
end

set(handles.textbox,'String', displayString);

由于某种原因,我的
楼层(位置(3))
不够。它给了我44个字符的值,但只适合41个字符。当我加载完整的53 ch字符串时,范围实际上是58。知道为什么会这样吗?在我的测试中,我使用了8的fontsize,使用更大的fontsize或其他字体可能会导致这种情况。你可能只需要使用一个像
0.9
这样的乘数就可以使它稍微短一点。我也使用了8的fontsize,在Sansserif女士中,这是一个单位问题,据我所知。。。我使用的是2015b自动取款机,这也可能会产生影响。我的单位是字符,单位是点数。我所看到的唯一区别是我正在运行2016a。