表格中的表格标题和滚动窗格通过以下方式隐藏:
Common.myTBL.setTableHeader(null);
Common.myScrollPanel.setColumnHeaderView(null);
Common.myScrollPanel.setViewportView(Common.myTBL);
pack();
当表中的列数很小时 - 比如5或6 - 我没有任何问题。
Common.myTBL.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
但是有一个特殊情况,列数为174(0到173)。最后一列未出现在屏幕上。我尝试添加一个额外的虚拟列(第175列),并且列174的部分出现了。
这是创建表模型和表对象的代码 public void createTableModel(){ int noOfColumns = 0; int noOfRows = 0; noOfRows = Common.tableData.size(); noOfColumns = Common.tableData.get(0).size(); System.out.println(“\ n VECTOR中的行数=”+ noOfRows); System.out.println(“\ n VECTOR中的列数=”+ noOfColumns); Common.myTableModel = new AttributiveCellTableModel(noOfRows,noOfColumns); System.out.println(“\ nNIN of MODEL of the Lines =”+ Common.myTableModel.getRowCount()); System.out.println(“\ nNIN中的列数= = + Common.myTableModel.getColumnCount()); Common.theRoots = Common.tableData.get(0); Common.myTableModel.setDataVector(Common.tableData,Common.theRoots); Common.cellAtt =(CellSpan)Common.myTableModel.getCellAttribute();
}
public void createTableObject(){
Common.myTBL = new MultiSpanCellTable(Common.myTableModel) {
public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
JComponent jcomp = (JComponent) comp;
Common.originalBorder = jcomp.getBorder();
comp.setBackground(setRowColor(Index_row));
jcomp.setToolTipText(getToolTip(Index_row, Index_col));
comp.setFont(Common.defaultFont14);
comp.setForeground(setGenderColor(Index_row, Index_col));
jcomp.setBorder(setBorderType(Index_row, Index_col));
return comp;
}
};
Common.myTBL.setRowHeight(25);
Common.myTBL.setBorder(null);
Common.myTBL.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
Common.myTBL.setCellSelectionEnabled(true);
Common.myTBL.setGridColor(new java.awt.Color(0, 51, 255));
Common.myTBL.setFillsViewportHeight(true);
Common.myTBL.revalidate();
}