Here you can find the source of getPaperTraysArray(PrintService ps)
public static Media[] getPaperTraysArray(PrintService ps)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.attribute.standard.Media; import javax.print.attribute.standard.MediaTray; public class Main { public static Media[] getPaperTraysArray(PrintService ps) { List<Media> list = getPaperTrays(ps); return Arrays.copyOf(list.toArray(), list.size(), Media[].class); }//from w ww . jav a2s. c o m public static Media[] getPaperTraysArray(String printerName) { PrintService ps = findPrintService(printerName); return getPaperTraysArray(ps); } public static List<Media> getPaperTrays(PrintService ps) { Media[] medias = (Media[]) ps.getSupportedAttributeValues(Media.class, null, null); List<Media> list = new ArrayList<>(); for (Media media : medias) { if (media instanceof MediaTray) { list.add(media); } } return list; } public static List<Media> getPaperTrays(String printerName) { PrintService ps = findPrintService(printerName); return getPaperTrays(ps); } public static PrintService findPrintService(String printerName) { PrintService printService = null; if (printerName == null || printerName.isEmpty()) { printService = PrintServiceLookup.lookupDefaultPrintService(); } else { PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); for (PrintService service : services) { String prtName = service.getName(); if (prtName.contains(printerName)) { printService = service; break; } } } return printService; } }