我的程序有一个包含100行空白行的JTable。让用户只填写10行。现在他只想打印顶部有标识的填充行。怎么做?
下面是我使用的代码:if(e.getSource() == print){
try {
table.print(JTable.PrintMode.FIT_WIDTH, head, null);
} catch (java.awt.print.PrinterException e1) {
System.err.format("Cannot print %s%n", e1.getMessage());
}
}
它只是打印所有的100行。
我想只打印填充的行(让前10行被填充)
可以在打印前过滤空行:
table.setAutoCreateRowSorter(true);
RowFilter filter = new RowFilter() {
public void include(Entry entry) {
// here add a loop which checks if
// any of the values in the entry is not-null
// return true if yes, false otherwise (that is all empty)
}
};
((DefaultRowSorter) table.getRowSorter()).setRowFilter(filter);
table.print(....);