tegz
asked on
auto resize jtable column width
i have a jtable and i want to be able to auto resize the width of the columns to fit the data.
how do i do this?
how do i do this?
ASKER
that doesnt resize according to the what i have stored in a particular column
The only way I have seen this done is to get the maximum length string in the column (by iteration and comparison) and use FontMetrics to calculate its size, then set the col width to that size.
ASKER
how do i get the maximum length string in a columns though?
any examples?
any examples?
>>
how do i get the maximum length string in a columns though?
any examples?
>>
Scan the table model and:
http://javaalmanac.com/egs/java.awt/TextDim.html
how do i get the maximum length string in a columns though?
any examples?
>>
Scan the table model and:
http://javaalmanac.com/egs/java.awt/TextDim.html
ASKER
for (int i = 0; i < tb.getColumnCount(); i++)
{
//get data length, how?
//set column prefered size?
}
{
//get data length, how?
//set column prefered size?
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i applied: http://javaalmanac.com/egs/javax.swing.table/PackCol.html
didnt change the code, it works all aprt from one long text field.
any ideas why?
didnt change the code, it works all aprt from one long text field.
any ideas why?
http://javaalmanac.com/egs/javax.swing.table/ColResize.html