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 (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?
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
table.getColumnModel().getColumn(col).setHeaderRenderer(new MyRenderer());
精彩评论