简体   繁体   English

获取特定JTable单元格中的前景(字体)

[英]Get foreground (font) in a particular JTable cell

There are many answers to how to set the font (use renderer), but I want to get this font. 有很多答案如何设置字体(使用渲染器),但我希望得到这个字体。 The reason why is for unit-testing: test for the renderer doing its job OK. 原因在于单元测试:测试渲染器是否正常工作。

The human eye can see whether a component for a given cell is rendered with a red foreground, but how can we do this programmatically? 人眼可以看到给定单元格的组件是否使用红色前景渲染,但我们如何以编程方式执行此操作?

later 后来
Just a word about my comment "get hold of the screen real estate". 只是关于我的评论“抓住屏幕房地产”。 That's not quite it: each one of these table cells contains something... but what? 这并不完全是:这些表格单元格中的每一个都包含一些内容......但是什么? And is it possible to reference it? 是否有可能参考它? It almost seems that each one is the "ghost" of the component (the same one) used successively to render each individual cell. 似乎每一个都是连续使用的组件(同一个)的“重影”,以呈现每个单独的单元格。 Obviously I don't really know about the "architecture" of the representation of a JTable. 显然,我并不真正了解JTable表示的“架构”。 Would be interesting to find out... although I suspect strongly that these "ghosts" (or whatever) are inaccessible. 有趣的是找出...虽然我强烈怀疑这些“幽灵”(或其他)是无法进入的。

Use the JTable.prepareRenderer(...) method. 使用JTable.prepareRenderer(...)方法。

This method will return the Component that will be used to do the rendering of the cell. 此方法将返回将用于执行单元格渲染的Component So you can then invoke the getForeground() method on the Component . 因此,您可以在Component上调用getForeground()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM