2

考虑以下将表格添加到 UIFigure 的代码:

hF = uifigure();
hT = uitable(hF, 'Position',[1 1 72 112], ...
  'Data', [ (5:5:20).' + "K", 100+zeros(4,1) + "%" ], ...
  'ColumnName', [compose("\x0394T"), "SR"], 'RowName', [],...
  'ColumnWidth', {30,40});
addStyle( hT, uistyle('HorizontalAlignment', 'center')); % Added in R2019b

这导致:

在此处输入图像描述

正如您在上面看到的,表格的标题仍然是左对齐的,并且字体大小比内容小 - 这看起来很不愉快。我希望标题居中对齐并具有相同或更大的字体大小。

我的问题是:如何更改标题的文本对齐方式和字体大小?

我正在使用 R2019b 更新 1。

4

1 回答 1

2

这可以通过执行几个修改<div class="mw-default-header-cell">元素样式的 JS 命令来完成:

% Get a webwindow handle:
hWin = struct(struct(struct(hF).Controller).PlatformHost).CEF;

% Execute some dojo commands:
hWin.executeJS('W = dojo.query("div[class=mw-default-header-cell]");');
hWin.executeJS('dojo.style(W[0], ''text-align'', ''center'');');
hWin.executeJS('dojo.style(W[1], ''text-align'', ''center'');');
hWin.executeJS('dojo.style(W[0], ''font-size'', ''12px'');');
hWin.executeJS('dojo.style(W[1], ''font-size'', ''12px'');');

导致:

在此处输入图像描述

请注意,dojo.query("div[class=mw-default-header-cell]")检索所有作为表头的 div,因此如果 UIFigure 中有多个表,或者不想修改表头,则必须注意索引 (of W) 进行修改。

于 2019-11-17T14:14:50.783 回答