简体   繁体   中英

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). 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?

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/

像下面这样的事情

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

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