我如何从java程序中打印文本?(JAVA)

Con*_*ure 0 java printing text

我甚至不知道这是否可能,我非常怀疑它,但如果可以的话,请你告诉我怎么样?我只是想知道如何从打印机打印一些文本.

有什么想法吗?

小智 7

这是更容易的事情.

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();

    }
}
Run Code Online (Sandbox Code Playgroud)

输出:弹出窗口

在此输入图像描述