0

I have a JTable with a column that has fairly long Strings in it, which causes that column's width to be extraordinarily huge. What I want to do is that when you load the table initially, the width of the column is set to a certain limit (so you don't have to scroll for an eternity to see the other of the columns), but you can still expand the column if you wish to view the rest of the column's contents.

How would I do this?

2 Answers2

1

with table.getColumnModel().getColumn(i).setWidth(100); you would set the column at i to the size of 100 pixels. if the string is too long, it will be visually cut , but the content can still be viewed by expanding the column.

XtremeBaumer
  • 6,275
  • 3
  • 19
  • 65
  • This is not exactly what I want to do though. If I `setMinWidth` to 100 and load the table, the full string will still be displayed initially. – Expect What Jan 10 '17 at 13:00
  • Nevermind, I got what I wanted. I noticed that every time the table is updated, the column width is reset again, and that part of the code was in a completely different place. – Expect What Jan 10 '17 at 13:32
  • @ExpectWhat, don't forget to "accept" the answer by clicking on the checkmark so people know the problem has been solved. – camickr Jan 10 '17 at 15:18
0

Have a look at the below article...it might be help with your requirement.

Auto resizing the JTable column widths

Community
  • 1
  • 1