1

I'm using a JTable :

public class MyPanel extends JPanel {

public MyPanel () {
   init()
}


init () {
DataModel model = new DataModel();
JTable table = new JTable (model);

TableColumnModel tcm = agentsTable.getColumnModel();
        tcm.getColumn(FIRST).setPreferredWidth(15);
        tcm.getColumn(SECOND).setPreferredWidth(100);
        tcm.getColumn(THIRD).setPreferredWidth(200);


        JScrollPane scroller = new JScrollPane();
        scroller.getViewport().add(table);
        this.add(scroller, BorderLayout.CENTER);
}

}


public class DataModel extends AbstractTableModel {

public final static int FIRST = 0;
public final static int SECOND = 1;
public final static int THIRD= 2;

...

}

the problem is every time i add a row to the model, the TableColumnModel seems to go back to default, and all the columns have the same width

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Adi Mor
  • 2,145
  • 5
  • 25
  • 44

1 Answers1

2

bet your custom TableModel fires a structureChanged on insert :-) That's incorrect, instead use fireTableRowsInserted().

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • @AdiMor - okay, so I lost and the error is somewhere else :-) Show a SSCCE – kleopatra Dec 08 '11 at 08:33
  • @trashgod - thanks for adding the link! Just removed that ugly grey background again, it's hurting the reading flow (mine, it least :-) – kleopatra Dec 08 '11 at 09:37