JavaFX Printer get printer list

Description

JavaFX Printer get printer list

import javafx.application.Application;
import javafx.collections.ObservableSet;
import javafx.print.Printer;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {

   public static void main(String[] args) {
      Application.launch(Main.class, args);
   }/*ww w  .  j  ava  2  s .  c  o  m*/
   @Override
   public void start(Stage primaryStage) {
      StackPane root = new StackPane();

      final Printer selectedPrinter = Printer.getDefaultPrinter();
      System.out.println(selectedPrinter.getName());

      ObservableSet<Printer> set = Printer.getAllPrinters();
      for(Printer p: set) {
         System.out.println(p.getName());
      }

      Scene scene = new Scene(root, 400, 400);
      primaryStage.setTitle("Printing from JavaFX");
      primaryStage.setScene(scene);
      primaryStage.show();
   }
}



PreviousNext

Related