简体   繁体   中英

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. Would be interesting to find out... although I suspect strongly that these "ghosts" (or whatever) are inaccessible.

Use the JTable.prepareRenderer(...) method.

This method will return the Component that will be used to do the rendering of the cell. So you can then invoke the getForeground() method on the Component .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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