开发者

How do I get a JTable header to display entire column names instead of shortening them?

开发者 https://www.devze.com 2023-04-01 10:43 出处:网络
I\'ve a JTable that I fill with a class that extends AbstractTableModel. The problem is that the columns are too short to display the column name. I\'ve turned off Jtable AutoResizeMode property, but

I've a JTable that I fill with a class that extends AbstractTableModel. The problem is that the columns are too short to display the column name. I've turned off Jtable AutoResizeMode property, but shortening still occ开发者_StackOverflowurs. How do I solve this?


You can use the Table Column Adjuster to adjust the column widths based on the header text.

The getColumnHeaderWidth(...) shows how to calculate the actual width using the header text and renderer.


Setting off autoresizemode only prevent the JTable's coumns to be resized. To force a particular width retrieve the table column model:

TableColumn column = jtable.getColumnModel().getColumn(col_num);

and set the desired width:

column.setPreferredWidth(width);


there are two ways

1) calculate PreferredSize from TableColumn (by defalut returns JLabel), there are 3-4 correct ways how to determine displayed TextLenght in pixex (please add plus 5-8 pixes moreover)

2) setPreferredSize directly, e.g. TableColumn#setPreferredSize

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号