I am a relatively new programmer so this may be a really simple question to answer but its got me a bit stumped..
I\'m trying to print my Java GUI\'s final output t
Create a JTextComponent
(I suggest a JTextArea
so you can use append()
), and append what you need to the field. Do not display it on the view, it is simply a hidden field for printing purposes.
All JTextComponent
s have a print()
method. Simply call hiddenTextArea.print()
and the rest is handled for you.
JTextArea hiddenTextArea = new JTextArea();
for (String s : dataToPrintCollection) {
hiddenTextArea.append(s + "\n");
}
try {
hiddenTextArea.print();
} catch (PrinterException e) {}