Hi,
I know that there are already several postings about the column width in a JTable. However I didn't find what I was looking for. In my table I want the first column (of four) to be a little bit wider than the others I know that therefore I use the setPrefferesWidth-method like
treeTable.getColumnModel().getColumn(0).setPreferredWidth(220);
treeTable.getColumnModel().getColumn(1).setPreferredWidth(70);
treeTable.getColumnModel().getColumn(2).setPreferredWidth(70);
treeTable.getColumnModel().getColumn(3).setPreferredWidth(70);
That works fine in the first place. When the GUI shows up the table columns are sized as wanted. Now the problem: The table is initially empty and gets filled with data on runtime. When the data is loaded the size of all columns falls back to the default settings. Also if a repeat the setting of the preferred width in the update method it doesnt have the desired effect.
A more complete snippet of my code is shown below:
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
add(mainPanel);
treeTable = new JXTreeTable( new CoverageTreeTableModel());
treeTable.setColumnControlVisible(true);
treeTable.setRootVisible(true);
treeTable.getColumnModel().getColumn(0).setPreferredWidth(220);
treeTable.getColumnModel().getColumn(1).setPreferredWidth(70);
treeTable.getColumnModel().getColumn(2).setPreferredWidth(70);
treeTable.getColumnModel().getColumn(3).setPreferredWidth(70);
treeTable.setRolloverEnabled(true);
JScrollPane tableScrollPane = new JScrollPane();
tableScrollPane.setViewportView(treeTable);
mainPanel.add(tableScrollPane);
I know that I'm working with a JXTreeTable but I experienced the same behaviour with a normal JTable.