Problems with a JTable

Hello folks,

i got two problems with a JTable.

1. how do I change the size of a table header?

2. I know that it is possible to set different column-sizes. The problem in my table is that I don't know how long some cells are. In this case, I want to to get the biggest cell of one column and set its size as the default size of that specific column.

Is that possilbe?

Hopefully you can help me out,

thank you

[453 byte] By [jorgeHX] at [2007-9-30 17:29:25]
# 1

A JTableHeader is just another Component, so you ought to be able to set its size like you would

any other component; however, since its function is to act as a header for a table, it might constrain

itself to fit the table.

In order to size the column to fit the largest cell, for each row, go through each column and get the

renderer component for that column (which configures the component for rendering) and get the width

of that component. If that's bigger than the column's current width, set its width and preferred width.

You'll also want to check the renderer component width for the header to make sure the header doesn't

get truncated if the column doesn't have a cell whose value is longer than the header.

: jay

JayDS at 2007-7-6 13:52:21 > top of Java-index,Archived Forums,Socket Programming...