How would I go about printing text from a java program? (Java)

后端 未结 4 1839
鱼传尺愫
鱼传尺愫 2021-01-16 05:38

I don\'t even know if this is possible and I highly doubt it is, but if you can, can you please tell me how? I just want to know how to print some text from a printer.

4条回答
  •  孤城傲影
    2021-01-16 06:27

    Here is something that is even easier.

    import javax.swing.JTextPane;
    import java.awt.print.PrinterException;
    
    public class TestPrint {
    
    
        public static void main(String[] args) throws PrinterException {
    
            JTextPane textPane = new JTextPane();
    
            textPane.setText("test text string - Hello World! Are you there?");
    
            textPane.print();
    
        }
    }
    

    Output: popup

提交回复
热议问题