获取JTable打印表格格式 [英] Get JTable to print tabular format
问题描述
您可以禁用网格线,例如...
JTable printTable = new JTable(table.getModel());
printTable.setSize(printTable.getPreferredSize());
JTableHeader tableHeader = printTable.getTableHeader();
tableHeader.setSize(tableHeader.getPreferredSize());
printTable.setShowHorizontalLines(false);
printTable.setShowVerticalLines(false);
printTable.print(JTable.PrintMode.FIT_WIDTH);
它使用一个临时的离线 JTable
来做实际的打印,所以你需要确保配置任何所需的渲染器,但想法是健全的。
这基本确保 JTable
在屏幕上并没有被更新,这可能会让用户感到害怕。
它也允许你如果你想要更改 TableHeader
;)
So I have a standard JTable and I want the user to be able to print it out. I used JTable.print() and that's fine for printing out an exact replica of the table, but I was hoping to have it more in a tabular format, with just the column names and then the data beneath them, no grids or anything. I thought this would be simple, but I have no clue what to do! Has anybody done this? If so, can someone provide me with code sample/example? Thank you.
You could disable the grid lines, for example...
JTable printTable = new JTable(table.getModel());
printTable.setSize(printTable.getPreferredSize());
JTableHeader tableHeader = printTable.getTableHeader();
tableHeader.setSize(tableHeader.getPreferredSize());
printTable.setShowHorizontalLines(false);
printTable.setShowVerticalLines(false);
printTable.print(JTable.PrintMode.FIT_WIDTH);
This uses a temporary, offscreen JTable
to do the actually printing, so you will need to be sure to configure any required renderers, but the idea is sound.
This basic ensures that the JTable
that is on the screen doesn't get updated with the changed, which could be kind of freaking to users.
It also allows you to change the TableHeader
should you want to to ;)
这篇关于获取JTable打印表格格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!