【问题标题】:How to control the style of uitable headers?如何控制 uitable headers 的样式?
【发布时间】:2020-03-13 01:00:42
【问题描述】:

考虑以下将表格添加到 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。

【问题讨论】:

    标签: matlab customization matlab-uitable matlab-app-designer undocumented-behavior


    【解决方案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]") 检索 所有 div 作为表头,因此如果 UIFigure 中有多个表,或者不想修改表头,则必须注意索引 ( W) 进行修改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      相关资源
      最近更新 更多