JavaFX Printer get name

Description

JavaFX Printer get name

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);
   }/*from ww  w . ja  v a2 s.co 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