如何控制uitableheaders的样式?
How to control the style of uitable headers?
考虑以下将 table 添加到 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
这导致:
正如您在上面看到的,table 的 header 仍然是 left-justified,并且字体比内容小 - 看起来很不愉快.我更喜欢 header center-justified 和相同或更大的字体大小。
我的问题是:如何更改 header 的文本对齐方式和字体大小?
我正在使用 R2019b 更新 1。
这可以通过执行几个修改 <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]")
检索 所有 个 table headers 的 div,所以如果有多个 table UIFigure 或 headers 不想修改,必须小心修改索引(W
)。
考虑以下将 table 添加到 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
这导致:
正如您在上面看到的,table 的 header 仍然是 left-justified,并且字体比内容小 - 看起来很不愉快.我更喜欢 header center-justified 和相同或更大的字体大小。
我的问题是:如何更改 header 的文本对齐方式和字体大小?
我正在使用 R2019b 更新 1。
这可以通过执行几个修改 <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]")
检索 所有 个 table headers 的 div,所以如果有多个 table UIFigure 或 headers 不想修改,必须小心修改索引(W
)。