Autosizing Column Headers

Hi all,

I am trying to use a list in the left hand side of a split pane and a table in the right hand side of the same split pane.

Both the list and the table are in scroll panes.

At the moment I am trying to have the table appear with column headings large enough to accommodate their names at runtime.

Can someone please tell me why the following code doesn't do this?

There is obviously more code which I can post if this is not the relevant section. Apologies in advance if that is the case.

public AvailableDocumentsPanel(){

// summary table in right scroll pane

summaryTable =new JTable(data, colHeadings);

// resize columns to size of headers.

for (int i = 0; i < summaryTable.getColumnCount(); i++){

summaryTable.getColumnModel().getColumn(i).sizeWidthToFit();

}

summaryTable.setFillsViewportHeight(true);

rightScrollPane =new JScrollPane(summaryTable);

// list in left scroll pane

vocationList =new JList(vocations);

vocationList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

vocationList.setSelectedIndex(0);

leftScrollPane =new JScrollPane(vocationList);

// add left and right scroll panes to split pane

summarySplitPane =new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftScrollPane, rightScrollPane);

// add split pane to Panel.

this.add(summarySplitPane);

}

[1994 byte] By [Zettaia] at [2007-11-27 3:08:37]
# 1
Swing forum: http://forum.java.sun.com/forum.jspa?forumID=57
DrLaszloJamfa at 2007-7-12 3:56:51 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks,Sorry about the wrong forum...
Zettaia at 2007-7-12 3:56:51 > top of Java-index,Java Essentials,New To Java...