Java 在一个PrinterJob中打印多个JPanel
到目前为止,我的情况如下: //选项卡是一个JTabbedPaneJava 在一个PrinterJob中打印多个JPanel,java,printing,Java,Printing,到目前为止,我的情况如下: //选项卡是一个JTabbedPane for(int i = 0; i < tab.getTabCount(); i ++){ if(tab.getComponent(i) instanceof DuctReport) PrintUtilities.printComponent(tab.getComponent(i), DuctReport.PRINT_SIZE); else if(tab.get
for(int i = 0; i < tab.getTabCount(); i ++){
if(tab.getComponent(i) instanceof DuctReport)
PrintUtilities.printComponent(tab.getComponent(i), DuctReport.PRINT_SIZE);
else if(tab.getComponent(i) instanceof Vandy)
PrintUtilities.printComponent(tab.getComponent(i), Vandy.PRINT_SIZE);
else
PrintUtilities.printComponent(tab.getComponent(i), .8);
}
当我做我所拥有的事情时,我必须为要打印的每个组件单独单击“打印”,我能在一个printerjob中打印所有组件吗
我还需要将组件置于页面中心,我尝试了以下操作:
g2d.translate((pageFormat.getImageableWidth()-componentToBePrinted.getWidth)/2,
pageFormat.getImageableY());
但在某些情况下,组件的宽度大于可成像宽度,有什么想法吗?尝试将每个JPanel添加到另一个JPanel:
JPanel wrapper = new JPanel();
for(JPanel panel : yourPanels){
wrapper.add(panel);
}
PrintUtilities.printComponent(wrapper, scale);
您可以将组件con[]作为打印作业的参数发送,然后相应地应用printutil递归
在数组中传递所有面板,并在print()函数中更改索引。遗憾的是,您的建议不起作用,它只打印了第一个面板one@Michael哦,我明白你想做什么了。让一个打印机作业处理多个页面的方法是通过一个可分页打印机。
JPanel wrapper = new JPanel();
for(JPanel panel : yourPanels){
wrapper.add(panel);
}
PrintUtilities.printComponent(wrapper, scale);