2013-04-01 29 views
0

我的程序包含一個帶有100個空白行的JTable。 讓用戶只填寫10行。現在他只想打印頂部帶有徽標的填充行。 如何做到這一點?僅打印來自帶有徽標的JTable的填充數據

這裏是我使用的代碼:

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行得到填補)

+0

怎麼樣檢查,如果行充滿,如果是然後打印出數據? – knowbody

+0

可以ü請發佈代碼。 – Praful

+0

您是否編寫了打印表格行的代碼?如果是這樣,請發佈。 –

回答

2

您可以在打印之前過濾空行:

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(....);