用于创建行标题的 JTable 自定义单元格渲染器
有人可以解释一下我如何创建行标题吗?我已经在 JTable 中设置了数据和标题文本:我想知道的是如何使用单元格渲染器获取第一列(即行标题列)并使其看起来像列标题(即第一个排)。现在它的背景是白色的,所以它看起来像常规数据。我希望它显示为灰色(或者我猜是非不透明的??)。哦,它也不应该是可选的。谢谢。
我刚刚意识到,水平滚动时它也应该保持原状,即即使有水平滚动条,它也应该始终出现在屏幕上。这可能吗?
**更新:** 我设法让它看起来像行标题。但我仍然不确定如何防止滚动。关于如何防止 JTable 第一列水平滚动有什么想法吗?
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 (i.e. the row header column) and make it look like the column headers (i.e. the first row). 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, i.e. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我讨厌回答我自己的问题,但这使我可以轻松修复第一列:
http://tips4java.wordpress.com/2008/11/05/fixed-column-table/
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/
像下面这样的事情应该做
Something like the following should do it