Есть таблица jTable, состоящая из 22 столбцов. Ей соответствует модель myTM: | Код | Object[][] data = {{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""},{""}}; Object[] columnnames = {"col1","col2","col3","col4","col5","col6","col7","col8","col9","col10","col11","col12","col13","col14","col15","col16","col17","col18","col19","col20","col21","col22"};
//...
JTable jTable = new JTable(myTM);
|
При этом таблица jTable находится внутри скроллпейна jScrollPane. Также таблице jTable я поставил модель столбцов mycm, в которой все стоблцы имеют одинаковую ширину: | Код | mytcm = jTable.getColumnModel(); mytc0 = mytcm.getColumn(0); mytc0.setWidth(100); mytc0.setPrefferedWidth(100); mytc1 = mytcm.getColumn(1); mytc1.setWidth(100); mytc1.setPrefferedWidth(100); mytc2 = mytcm.getColumn(2); mytc2.setWidth(100); mytc2.setPrefferedWidth(100); mytc3 = mytcm.getColumn(3); mytc3.setWidth(100); mytc3.setPrefferedWidth(100); mytc4 = mytcm.getColumn(4); mytc4.setWidth(100); mytc4.setPrefferedWidth(100); mytc5 = mytcm.getColumn(5); mytc5.setWidth(100); mytc5.setPrefferedWidth(100); mytc6 = mytcm.getColumn(6); mytc6.setWidth(100); mytc6.setPrefferedWidth(100); mytc7 = mytcm.getColumn(7); mytc7.setWidth(100); mytc7.setPrefferedWidth(100); mytc8 = mytcm.getColumn(8); mytc8.setWidth(100); mytc8.setPrefferedWidth(100); mytc9 = mytcm.getColumn(9); mytc9.setWidth(100); mytc9.setPrefferedWidth(100); mytc10 = mytcm.getColumn(10); mytc10.setWidth(100); mytc10.setPrefferedWidth(100); mytc11 = mytcm.getColumn(11); mytc11.setWidth(100); mytc11.setPrefferedWidth(100); mytc12 = mytcm.getColumn(12); mytc12.setWidth(100); mytc12.setPrefferedWidth(100); mytc13 = mytcm.getColumn(13); mytc13.setWidth(100); mytc13.setPrefferedWidth(100); mytc14 = mytcm.getColumn(14); mytc14.setWidth(100); mytc14.setPrefferedWidth(100); mytc15 = mytcm.getColumn(15); mytc15.setWidth(100); mytc15.setPrefferedWidth(100); mytc16 = mytcm.getColumn(16); mytc16.setWidth(100); mytc16.setPrefferedWidth(100); mytc17 = mytcm.getColumn(17); mytc17.setWidth(100); mytc17.setPrefferedWidth(100); mytc18 = mytcm.getColumn(18); mytc18.setWidth(100); mytc18.setPrefferedWidth(100); mytc19 = mytcm.getColumn(19); mytc19.setWidth(100); mytc19.setPrefferedWidth(100); mytc20 = mytcm.getColumn(20); mytc20.setWidth(100); mytc20.setPrefferedWidth(100); mytc21 = mytcm.getColumn(21); mytc21.setWidth(100); mytc21.setPrefferedWidth(100); jTableHeader = jTable.getTableHeader(); jTableHeader.setSize(2200, 32); jTableHeader.setPreferredSize(new Dimension(2200, 32)); jTableHeader.setMaximumSize(new Dimension(2200, 32)); jTableHeader.setMinimumSize(new Dimension(2200, 32)); jTableHeader.setColumnModel(jthcm); jTableHeader.setResizingAllowed(true); jTableHeader.setVisible(true); jTable.setTableHeader(jTableHeader); jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); for (j=0; j<22; j++) { mytc = mytcm.getColumn(j); mytc.setResizable(true); } jTable.setColumnModel(mytcm);
|
(Здесь mytcm имеет тип TableColumnModel, а mytc0, ..., mytc21, mytc имеют тип TableColumn). Одно время я проводил какие-то манимпуляции с количеством столбов в таблице (изменил их число до 14), потом опять восстановил прежний вид таблицы (число столбцов равно 22). В результате чего при горизонтальной прокрутке скроллпейна отображается содержимое всех 22 столбцов таблицы, но что касается заголовков столбцов, то отображаются заголовки только 14 столбцов, а заголовки оставшихся 8 стоблцов--пустые. Как сделать так, чтобы при горизонтальной прокрутке отображались заголовки всех 22 стоблцов (то есть чтобы отображались заголовки не только столбцов "col1", ..., "col14" , но также и заголовки столбцов "col15", ..., "col22")?
|