Hi
My code reorder columns and calls fireTableStructureChanged. But it
doesn't work. All I see is the default order of columns. Please see the
code below. Thanks for your help
for(int i=0;i<count;i++) {
int width=(int)(ttsDefaults.getColumnWidth(i)*
DesktopEnvironment.getInstance().getDesktopRootFrame().getWidth());
sumWidth+=width;
String name= (String) (ttsDefaults.getColumnName(i));
treeTable.getColumnModel().getColumn(i).setPreferredWidth(width);
treeTable.getColumnModel().getColumn(i).setHeaderValue(name);
System.out.println(" i=" + i + " name=" + name +
"**********");
//treeTable.setAutoCreateColumnsFromModel( false );
//treeTable.getColumnModel().getColumn(i).setWidth(width);
}
treeTable.getTableModel().fireTableStructureChanged();
soup_or_power@yahoo.com - 22 Nov 2005 22:16 GMT
I am able to get some partial results using JTable's moveColumn method.
I am posting the partially done method. I don't know how to improve it
so it works like bullet proof. I'd appreciate any help from the
audience here.
for(int i=0;i<count;i++) {
int width=(int)(ttsDefaults.getColumnWidth(i)*
DesktopEnvironment.getInstance().getDesktopRootFrame().getWidth());
sumWidth+=width;
String name= (String) (ttsDefaults.getColumnName(i));
treeTable.getColumnModel().getColumn(i).setPreferredWidth(width);
//treeTable.getColumnModel().getColumn(i).setHeaderValue(name);
//System.out.println(" i=" + i + " name=" + name +
"**********");
int s1=0;
String hd=(String)
treeTable.getColumnModel().getColumn(i).getHeaderValue();
System.out.println(" name= " + name + " modelhdr=" + hd +
"**********" + "iter=" + i);
if (name.trim().equals("") == false && name.equals(hd) ==
false) {
System.out.println("these two should be swapped");
for (int j=0; j <
treeTable.getTableModel().getColumnCount(); j++)
{
String n1= (String)
treeTable.getColumnModel().getColumn(j).getHeaderValue();
if (name.trim().equals("") == false && name.equals(n1) ==
true) {
s1=j;
//treeTable.getColumnModel().getColumn(i).setHeaderValue(name);
System.out.println("origplace=" + s1 +
"**************of" + n1 + " now at " + i);
break;
}
}
//System.out.println("xml val=" + i + " modelval = " +
s1);
}
if (s1 > 0)
{
System.out.println("swapping columns" + i + " " + s1);
treeTable.moveColumn(i, s1);
//treeTable.moveColumn(s1, i);
treeTable.revalidate();
}