AutoFit column like excel in JTable

how to make autofit column like excel in JTable.so if my text is longer then my column size so my column will fit it.and horizontal scroll appear if my table size is longer.
[194 byte] By [Xeon-YKa] at [2007-10-3 2:42:11]
# 1

Please ask Swing questions in the Swing forum next time.

Roughly about the first part - because I don't know and won't bother to look it up: FontMetrics can tell you how long a certain String is in pixels. You can set the column's width to a value larger than that on each value submission.

About the second part: put your JTable into a JScrollPane.

CeciNEstPasUnProgrammeura at 2007-7-14 19:40:57 > top of Java-index,Java Essentials,New To Java...
# 2

Here's the source code for a full standalone utility class I posted a few years back.

http://forum.java.sun.com/thread.jspa?forumID=54&messageID=2532529&threadID=527301

It'll resizes any JTable you pass to it.

But you will want to put your JTable in a scrollpane to allow for large JTables beyond the width of the screen / window.

regards,

Owen

omcgoverna at 2007-7-14 19:40:57 > top of Java-index,Java Essentials,New To Java...