删除表格
可用自己定义的 tableModel 的方法 removeRow()
执行这个方法后,会自动把 model 中的 vector 删除那行的数据
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
设置表格的列宽不扩展,列宽随内容和表头的最大宽度
public void FitTableColumns(JTable myTable) { //设置table的列宽随内容宽度调整
JTableHeader header = myTable.getTableHeader();
int rowCount = myTable.getRowCount();
Enumeration columns = myTable.getColumnModel().getColumns();
while (columns.hasMoreElements()) {
TableColumn column = (TableColumn) columns.nextElement();
int col = header.getColumnModel().getColumnIndex(
column.getIdentifier());
int width = (int) myTable.getTableHeader().getDefaultRenderer()
.getTableCellRendererComponent(myTable,
column.getIdentifier(), false, false, -1, col)
.getPreferredSize().getWidth();
for (int row = 0; row < rowCount; row++) {
int preferedWidth = (int) myTable.getCellRenderer(row, col)
.getTableCellRendererComponent(myTable,
myTable.getValueAt(row, col), false, false,
row, col).getPreferredSize().getWidth();
width = Math.max(width, preferedWidth);
}
header.setResizingColumn(column);
column.setWidth(width + myTable.getIntercellSpacing().width);
}
}
// System.out.println(map_tableEnglishname_tableCnname);
// System.out.println("====================");
// Set s=map_tableEnglishname_tableCnname.entrySet();
// Iterator iterator=s.iterator();
// while(iterator.hasNext()){
// Map.Entry map=(Map.Entry)iterator.next();
// System.out.print(map+"/t");
// System.out.println("Key:"+map.getKey()+"/t value:"+map.getValue());
// }
可用自己定义的 tableModel 的方法 removeRow()
执行这个方法后,会自动把 model 中的 vector 删除那行的数据
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
设置表格的列宽不扩展,列宽随内容和表头的最大宽度
public void FitTableColumns(JTable myTable) { //设置table的列宽随内容宽度调整
JTableHeader header = myTable.getTableHeader();
int rowCount = myTable.getRowCount();
Enumeration columns = myTable.getColumnModel().getColumns();
while (columns.hasMoreElements()) {
TableColumn column = (TableColumn) columns.nextElement();
int col = header.getColumnModel().getColumnIndex(
column.getIdentifier());
int width = (int) myTable.getTableHeader().getDefaultRenderer()
.getTableCellRendererComponent(myTable,
column.getIdentifier(), false, false, -1, col)
.getPreferredSize().getWidth();
for (int row = 0; row < rowCount; row++) {
int preferedWidth = (int) myTable.getCellRenderer(row, col)
.getTableCellRendererComponent(myTable,
myTable.getValueAt(row, col), false, false,
row, col).getPreferredSize().getWidth();
width = Math.max(width, preferedWidth);
}
header.setResizingColumn(column);
column.setWidth(width + myTable.getIntercellSpacing().width);
}
}
// System.out.println(map_tableEnglishname_tableCnname);
// System.out.println("====================");
// Set s=map_tableEnglishname_tableCnname.entrySet();
// Iterator iterator=s.iterator();
// while(iterator.hasNext()){
// Map.Entry map=(Map.Entry)iterator.next();
// System.out.print(map+"/t");
// System.out.println("Key:"+map.getKey()+"/t value:"+map.getValue());
// }