Hi All,
I'm attempting to set the width of some columns in a JTable to the size
of their column header's plus the column margin.
I call the following method for each column in the table. I don't want
some columns to have a fixed size hence the boolean.
private void setColumnWidth(JTable jTableIn, int intIn, boolean
booleanIn)
{
String value = jTableIn.getColumnName(intIn);
JTableHeader jHeader = jTableIn.getTableHeader();
FontMetrics metrics =
jTableIn.getGraphics().getFontMetrics(jHeader.getFont());
int width = metrics.stringWidth(value) + (2 *
jHeader.getColumnModel().getColumnMargin());
if (booleanIn)
{
jTableIn.getColumnModel().getColumn(intIn).setMaxWidth(width);
jTableIn.getColumnModel().getColumn(intIn).setMinWidth(width);
}
jTableIn.getColumnModel().getColumn(intIn).setPreferredWidth(width);
}
The problem is that the text in the headers in always truncated, which
is not what I expect. Any suggestions as to how I can do this better.
Thanks,
MrFred.
hiwa - 30 Nov 2006 02:54 GMT
> Hi All,
>
[quoted text clipped - 29 lines]
>
> MrFred.
This thread may help:
http://forum.java.sun.com/thread.jspa?threadID=701058