【问题标题】:How to get colour, font of java table row/cell/text with Jemmy?如何使用 Jemmy 获取 java 表格行/单元格/文本的颜色、字体?
【发布时间】:2016-05-25 07:52:12
【问题描述】:

需要在 Swing 应用程序中检查 java 表格(文本、背景)的颜色/字体样式,因为行的样式应该取决于列值。

可以获取所选(单元格/行)的字体和背景颜色:

mainTable.selectCell(0, 0);
String bgcol = mainTable.getSelectionBackground().toString();  // => javax.swing.plaf.ColorUIResource[r=51,g=153,b=255]
String fgcol = mainTable.getSelectionForeground().toString();  // => javax.swing.plaf.ColorUIResource[r=255,g=255,b=255]    

但是选中的单元格/行有自己的选择风格,所以这个检查就变得毫无用处了。

使用 Jemmy 库对任何单元格/行(不仅仅是选定的)进行样式检查的方法是什么?

【问题讨论】:

    标签: java swing automated-tests jemmy


    【解决方案1】:

    渲染器用于绘制表格中的每个单元格。您应该能够使用以下代码访问用于呈现单元格的组件:

    TableCellRenderer renderer = table.getCellRenderer(row, column);
    Component c = table.prepareRenderer(renderer, row, column);
    System.out.println(c.getBackground());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      相关资源
      最近更新 更多