JTable を完全に印刷することはできますが、実際には JTable の特定の部分 (行 10 から行 50、列 70 から列 150 など) だけを印刷したいと考えています。
2215 次
2 に答える
2
私もこの問題に直面しました。印刷前に列を非表示にし、印刷後に列を復元することで解決:
// get column num from settings
int num = gridSettings.getColumnsOnPage();// first <num> columns of the table will be printed
final TableColumnModel model = table.getColumnModel();
// list of removed columns. After printing we add them back
final List<TableColumn> removed = new ArrayList<TableColumn>();
int columnCount = model.getColumnCount();
// hiding columns which are not used for printing
for(int i = num; i < columnCount; ++i){
TableColumn col = model.getColumn(num);
removed.add(col);
model.removeColumn(col);
}
// printing after GUI will be updated
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// table printing
try {
table.print(PrintMode.FIT_WIDTH, null, null, true, hpset, true); // here can be your printing
} catch (PrinterException e) {
e.printStackTrace();
}
// columns restoring
for(TableColumn col : removed){
model.addColumn(col);
}
}
});
JTable の特定の部分を印刷するには、このコードを少し変更するだけです。
于 2013-12-26T10:31:37.817 に答える
1
選択したフラグメントのセル境界を取得し、目的の領域を計算し ( Rectangle
)、目的の領域のみをペイントするようにクリップ領域を定義し、印刷可能でGraphics's
translate() メソッドを使用してレンダリングをシフトします。
于 2013-02-21T13:55:37.613 に答える