Java JComboBox getPrinterJComboBox()

Here you can find the source of getPrinterJComboBox()

Description

get Printer J Combo Box

License

Open Source License

Declaration

public static JComboBox<String> getPrinterJComboBox() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

import javax.swing.JComboBox;

public class Main {
    public static JComboBox<String> getPrinterJComboBox() {
        JComboBox<String> box = new JComboBox<>();
        PrintService[] services = PrintServiceLookup.lookupPrintServices(
                null, null);/*from   w w w  .j a  v  a  2 s.co  m*/
        for (PrintService printService : services) {
            box.addItem(printService.getName());
        }

        // Set to default printer
        box.setSelectedItem(getDefaultPrinterName());

        return box;
    }

    public static String getDefaultPrinterName() {
        if (PrintServiceLookup.lookupDefaultPrintService() != null) {
            return PrintServiceLookup.lookupDefaultPrintService().getName();
        }
        return ""; // no default printer specified
    }
}

Related

  1. getComboBoxDisabledBackground()
  2. getEOL(JComboBox eolCombo)
  3. getJComboBoxString(JComboBox comboBox)
  4. getMaxWidth(final JComboBox combo, final FontMetrics fm)
  5. getOnlyComboBox(Container owner)
  6. getScrollBarWidth(JComboBox comboBox, JScrollPane scrollPane)
  7. initCombo(JComboBox combo)
  8. inputComboBox(JComboBox cbx, String[] str)
  9. isCbEquals(JComboBox cb, String str)