【问题标题】:printing only filled data from JTable with logo仅打印带有徽标的 JTable 中的填充数据
【发布时间】:2013-04-01 09:31:06
【问题描述】:

我的程序有一个有 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 行被填充)

【问题讨论】:

  • 如何检查行是否已填充,如果是则打印数据?
  • 你能把代码贴出来吗。
  • 您是否编写了代码来打印表格的行?如果有,请发布。
  • 你只需对 10 行执行 for 循环。然后table.getValueAt(row, column).toString(); 检查这个.equals("") 是否显示你到目前为止做了什么
  • 你能把代码贴出来,这不是本网站的工作方式:通常,必须写你的解决你的问题的代码。你会打赌帮助你被困住的部分。如果您不知道如何遍历表的值,则应该退后一步并阅读一些基础知识(循环等语言功能和/或 JTable 等特定于类的 api)

标签: java swing printing jtable rowfilter


【解决方案1】:

您可以在打印前过滤空行:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 2012-12-26
    • 2022-11-13
    • 2012-10-31
    • 1970-01-01
    • 2019-04-25
    相关资源
    最近更新 更多