简体   繁体   English

JTable自定义单元格渲染器创建行标题

[英]JTable custom cell renderer to create row header

Can somebody please explain how I would create row headers? 有人可以解释一下如何创建行标题吗? I already have the data and header texts set in the JTable: all I want to know is how I can use a cell renderer to take that first column (ie the row header column) and make it look like the column headers (ie the first row). 我已经在JTable中设置了数据和标题文本:我想知道的是如何使用单元格渲染器获取第一列(即行标题列)并使它看起来像列标题(即第一行)行)。 Right now its background is white, so it looks like regular data. 现在它的背景是白色的,因此看起来像常规数据。 I want it to appear gray (or non-opaque I guess??). 我希望它显示为灰色(我猜是非透明的??)。 Oh and it should also not be selectable. 哦,它也不应该是可选的。 Thanks. 谢谢。

I just realized that it should also remain put when scrolling horizontally, ie it should always appear on the screen even if there is a horizontal scroll bar. 我只是意识到,在水平滚动时它也应该保持原样,即即使有水平滚动条它也应始终出现在屏幕上。 Is this even possible? 这有可能吗?

**Update: ** I managed to get it to look like the row headers. **更新:**我设法使它看起来像行标题。 But I am still not sure how to prevent scrolling. 但是我仍然不确定如何防止滚动。 Any ideas on how to prevent horizontal scrolling on the first column of a JTable? 关于如何防止在JTable的第一列上进行水平滚动的任何想法?

I hate to answer my own question, but this allowed me to easily fix the first column: 我不愿回答自己的问题,但这使我可以轻松修复第一列:

http://tips4java.wordpress.com/2008/11/05/fixed-column-table/ http://tips4java.wordpress.com/2008/11/05/fixed-column-table/

像下面这样的事情

table.getColumnModel().getColumn(col).setHeaderRenderer(new MyRenderer());

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

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