Last active
January 3, 2016 20:58
-
-
Save twyatt/8518116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.event.EventHandler; | |
import javafx.print.PrinterJob; | |
import javafx.scene.Scene; | |
import javafx.scene.input.MouseEvent; | |
import javafx.scene.layout.Pane; | |
import javafx.scene.shape.Rectangle; | |
import javafx.stage.Stage; | |
public class PrintTest extends Application { | |
private Pane root; | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(final Stage primaryStage) throws Exception { | |
root = new Pane(); | |
root.setOnMouseClicked(new EventHandler<MouseEvent>() { | |
@Override | |
public void handle(MouseEvent e) { | |
PrinterJob printerJob = PrinterJob.createPrinterJob(); | |
System.out.println("Printing..."); | |
if (printerJob.showPrintDialog(primaryStage.getOwner()) && printerJob.printPage(root)) { | |
System.out.println("Print successful."); // <-- this line is never reached on OS X | |
printerJob.endJob(); | |
} | |
} | |
}); | |
Rectangle r = new Rectangle(); | |
r.setX(50); | |
r.setY(50); | |
r.setWidth(200); | |
r.setHeight(100); | |
r.setArcWidth(20); | |
r.setArcHeight(20); | |
root.getChildren().add(r); | |
Scene scene = new Scene(root, 800, 600); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment