打印(JavaFX)时窗格大小的问题

时间:2019-01-05 12:17:55

标签: javafx-8

在我应该打印的stackpane类下面,并具有打印窗格的功能。但它不能正常工作。我正在打印机上接受如下图所示的内容。请帮助,我搜索了我的错误,否,我找不到它。谢谢。out to print like this

public class PrintPane {

static StackPane root = new StackPane();
static Label status = new Label();
static ImageView refresh = new ImageView("images/refresh.png");
static TableView tableRegistration = new TableView();
static TableColumn department = new TableColumn("Цех");
static TableColumn station = new TableColumn("Станция");
static TableColumn object = new TableColumn("Обект");
static TableColumn leftDays = new TableColumn("Количество оставшихся дней");
static TableColumn detail = new TableColumn("Деталь");
static TableColumn lastCheck = new TableColumn("Дата последней проверки");
static TableColumn nextCheck = new TableColumn("Дата новой проверки");
static TableColumn detailName = new TableColumn("Наименование детали");
static TableColumn location = new TableColumn("Расположение");
static TableColumn detailCode = new TableColumn("Код детали");

public static StackPane printTable() {

    department.setCellValueFactory(new PropertyValueFactory("department"));
    station.setCellValueFactory(new PropertyValueFactory("station"));
    object.setCellValueFactory(new PropertyValueFactory("object"));
    leftDays.setCellValueFactory(new PropertyValueFactory("leftDays"));
    detail.setCellValueFactory(new PropertyValueFactory("detail"));
    lastCheck.setCellValueFactory(new PropertyValueFactory("lastCheck"));
    nextCheck.setCellValueFactory(new PropertyValueFactory("nextCheck"));
    location.setCellValueFactory(new PropertyValueFactory("location"));
    detailCode.setCellValueFactory(new PropertyValueFactory("registrationID"));

    tableRegistration.getColumns().addAll(department, station, object, leftDays,
            detail, lastCheck, nextCheck, location, detailCode);
    tableRegistration.setItems(DataProcess.selectDataFromRegistration());
    tableRegistration.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    status.setText("There should be written something about tables below. Report");
    status.setStyle(Style.styleLabel);
    refresh.setFitHeight(60);
    refresh.setFitWidth(60);
    tableRegistration.setStyle(Style.styleTable);

    HBox hb = new HBox();
    hb.getChildren().addAll(status, refresh);
    hb.setPadding(new Insets(5, 5, 5, 5));
    hb.setSpacing(5);
    hb.setAlignment(Pos.CENTER);
    VBox vb = new VBox();
    vb.getChildren().addAll(hb, tableRegistration);
    vb.setSpacing(5);
    vb.setPadding(new Insets(10, 10, 10, 10));
    root.getChildren().add(vb);
    return root;
   }
}

和我的通话打印功能:

{
   btnPrint.setOnAction(e -> {
       printNode(PrintPane.printTable);
   });
}

这是我的打印功能:

{

  public static void printNode(final Node node) {
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout
    = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.HARDWARE_MINIMUM);
PrinterAttributes attr = printer.getPrinterAttributes();
PrinterJob job = PrinterJob.createPrinterJob();
double scaleX
    = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
double scaleY
    = pageLayout.getPrintableHeight() / node.getBoundsInParent().getHeight();
Scale scale = new Scale(scaleX, scaleY);
node.getTransforms().add(scale);

if (job != null && job.showPrintDialog(node.getScene().getWindow())) {
  boolean success = job.printPage(pageLayout, node);
  if (success) {
    job.endJob();

  }
}
node.getTransforms().remove(scale);
 }
}

0 个答案:

没有答案