Adjust column widths of JTable

G

Gerhard Rapp

Hi all.

I try to automatically adjust the column widths of a JTable according to
their content. My ideas were (1) to search the longest entry for each column
by going through all entries. (Which is pretty slow for long tables) And (2)
to adapt the getValueAt function to detect and store the longest entry for
each column, so I can set these values when the table is displayed the first
time. Btw. which event handler will I have to use here?

I guess some of you have faced this problem before. What are your solutions?

In this context I have another question? If the sum of the column widths is
greater than the width of the table's scroll pane one has to set the
autoresize strategy property of the table to OFF. If the total width is less
than the scroll panes' width one gets an annoying border around the table.
How can I prevent this? Apart from adding a dummy column at the right. And
what about the rows?

Thanks
Gerhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top