import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.print.PrinterJob; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.PasswordField; import javafx.stage.Stage; public class PrintTextField extends Application { private void init(Stage primaryStage) { VBox root = new VBox(); Scene scene = new Scene(root, 500, 300); primaryStage.setScene(scene); final HBox content = new HBox();; Button button = new Button("Print"); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { PrinterJob job = PrinterJob.createPrinterJob(); if (job != null && job.showPrintDialog(null)) { job.printPage(content); job.endJob(); } } }); Label label1 = new Label("First Name:"); TextField textfield1 = new TextField(); textfield1.setPromptText("first name"); textfield1.setMaxWidth(80); Label label2 = new Label("Last Name:"); TextField textfield2 = new TextField(); textfield2.setPromptText("last name"); textfield2.setMaxWidth(80); Label label3 = new Label("Email:"); TextField textfield3 = new TextField(); textfield3.setPromptText("email"); textfield3.setMaxWidth(100); content.getChildren().addAll(label1, textfield1, label2, textfield2, label3, textfield3); content.setSpacing(10); root.setSpacing(50); root.getChildren().addAll(button, content); } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); primaryStage.setTitle("HBox Printing(" + System.getProperty("javafx.runtime.version") + ")"); primaryStage.show(); } public static void main(String[] args) { launch(args); } }