Printing 继续打印,不要将我的tablecolumn标题一分为二

Printing 继续打印,不要将我的tablecolumn标题一分为二,printing,javafx-8,Printing,Javafx 8,我打印tableview时遇到问题。标题被切成两半,如下所示: 这是我的代码: @FXML private void printAllFlowers(ActionEvent event) throws IOException { Printer printer = Printer.getDefaultPrinter(); //get the default printer javafx.print.PageLayout pageLayout = printer.createPa

我打印tableview时遇到问题。标题被切成两半,如下所示:

这是我的代码:

@FXML
private void printAllFlowers(ActionEvent event) throws IOException {
    Printer printer = Printer.getDefaultPrinter(); //get the default printer
    javafx.print.PageLayout pageLayout = printer.createPageLayout(Paper.NA_LETTER, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT); //create a pagelayout.  I used Paper.NA_LETTER for a standard 8.5 x 11 in page.
    PrinterJob job = PrinterJob.createPrinterJob();//create a printer job

    if (job.showPrintDialog(tblFlower.getScene().getWindow()))// this is very useful it allows you to save the file as a pdf instead using all of your printer's paper. A dialog box pops up, allowing you to change the "name" option from your default printer to Adobe pdf.
    {
        double pagePrintableWidth = pageLayout.getPrintableWidth(); //this should be 8.5 inches for this page layout.
        double pagePrintableHeight = pageLayout.getPrintableHeight();// this should be 11 inches for this page layout.

        tblFlower.prefHeightProperty().bind(Bindings.size(tblFlower.getItems()).multiply(Bindings.size(tblFlower.getItems()).add(1.0)));// If your cells' rows are variable size you add the .multiply and play with the input value until your output is close to what you want. If your cells' rows are the same height, I think you can use .multiply(1). This changes the height of your tableView to show all rows in the table.
        tblFlower.minHeightProperty().bind(tblFlower.prefHeightProperty());//You can probably play with this to see if it's really needed.  Comment it out to find out.
        tblFlower.maxHeightProperty().bind(tblFlower.prefHeightProperty());//You can probably play with this to see if it' really needed.  Comment it out to find out.


        double scaleX = pagePrintableWidth / tblFlower.getBoundsInParent().getWidth();//scaling down so that the printing width fits within the paper's width bound.

        double numberOfPages = Math.ceil((tblFlower.getPrefHeight() * scaleX) / pagePrintableHeight);//used to figure out the number of pages that will be printed.

        tblFlower.getTransforms().add(new Scale(scaleX, (scaleX)));//scales the printing. Allowing the width to stay within the papers width, and scales the height to do away with skewed letters and images.
        tblFlower.getTransforms().add(new Translate(0, 0));// starts the first print at the top left corner of the image that needs to be printed

        //Since the height of what needs to be printed is longer than the paper's heights we use gridTransfrom to only select the part to be printed for a given page.
        Translate gridTransform = new Translate();
        tblFlower.getTransforms().add(gridTransform);

        //now we loop though the image that needs to be printed and we only print a subimage of the full image.
        //for example: In the first loop we only pint the printable image from the top down to the height of a standard piece of paper. Then we print starting from were the last printed page ended down to the height of the next page. This happens until all of the pages are printed.
        // first page prints from 0 height to -11 inches height, Second page prints from -11 inches height to -22 inches height, etc.
        for (int i = 0; i < numberOfPages; i++) {
            gridTransform.setY(-i * (pagePrintableHeight / scaleX));
            job.printPage(pageLayout, tblFlower);
        }

        job.endJob();//finally end the printing job.
    }
@FXML
私有void printAllFlowers(ActionEvent事件)引发IOException{
打印机打印机=打印机。getDefaultPrinter();//获取默认打印机
javafx.print.PageLayout PageLayout=printer.createPageLayout(Paper.NA_-LETTER,PageOrientation.LANDSCAPE,printer.MarginType.DEFAULT);//创建一个页面布局。我使用Paper.NA_-LETTER作为标准的8.5 x 11英寸页面。
PrinterJob job=PrinterJob.createPrinterJob();//创建打印机作业
if(job.showPrintDialog(tblFlower.getScene().getWindow())//这非常有用,它允许您将文件保存为pdf格式,而不是使用打印机的所有纸张。弹出一个对话框,允许您将“名称”选项从默认打印机更改为Adobe pdf。
{
double pagePrintableWidth=pageLayout.getPrintableWidth();//此页面布局应为8.5英寸。
double pagePrintableHeight=pageLayout.getPrintableHeight();//此页面布局应为11英寸。
tblFlower.prefHeightProperty().bind(Bindings.size(tblFlower.getItems()).multiply(Bindings.size(tblFlower.getItems()).add(1.0));//如果单元格的行大小可变,则添加.multiply并使用输入值,直到输出接近所需值。如果单元格的行高度相同,则可以使用.multiply(1)。这将更改tableView的高度以显示表中的所有行。
tblFlower.minHeightProperty().bind(tblFlower.prefHeightProperty());//您可能可以使用它来查看是否确实需要它。请对其进行注释以了解情况。
tblFlower.maxHeightProperty().bind(tblFlower.prefHeightProperty());//您可能可以使用它来查看是否真的需要它。对它进行注释以了解情况。
double scaleX=pagePrintableWidth/tblFlower.getBoundsInParent().getWidth();//缩小比例,使打印宽度符合纸张的宽度限制。
double numberOfPages=Math.ceil((tblFlower.getPrefHeight()*scaleX)/pagePrintableHeight);//用于计算将要打印的页数。
tblFlower.getTransforms().add(新比例(scaleX,(scaleX));//缩放打印。允许宽度保持在纸张宽度范围内,并缩放高度以消除倾斜的字母和图像。
tblFlower.getTransforms().add(new Translate(0,0));//在需要打印的图像的左上角开始第一次打印
//由于需要打印的部分的高度比纸张的高度长,因此我们使用gridTransfrom仅为给定页面选择要打印的部分。
Translate gridTransform=新的Translate();
tblFlower.getTransforms().add(gridTransform);
//现在我们循环遍历需要打印的图像,只打印完整图像的子图像。
//例如:在第一个循环中,我们只从上到下将可打印图像缩小到标准纸张的高度。然后我们从最后一页开始打印,一直到下一页的高度。直到所有页面都打印出来为止。
//第一页打印高度从0到-11英寸,第二页打印高度从-11英寸到-22英寸,以此类推。
对于(int i=0;i
有人能告诉我为什么它会把我的头剪掉吗