Reputation: 53
my program hava a JTable with 100 blank rows. Let user fills only 10 rows. Now he want to print only the filled rows with a logo on the top. How to do it ?
Here is the code i used:
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());
}
}
It simply prints all the 100 rows.
I want to print only the filled rows( let first 10 rows get filled)
Upvotes: 0
Views: 395
Reputation: 51536
you can filter the empty rows before printing:
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(....);
Upvotes: 2