Search code examples
javaswingprintingjtablegraphics2d

JTable print with prefix text on top (not header / footer)


I would like to print a specific text on the top of a JTable , but not in every page (not header) just on the first page and/or a text on the end of the text but again not as a footer to each page but only after the end of the JTable contents.

How is this possible ? Thank you!


Solution

  • JTable has a version of print() you could probably use an example. Take a look at the source code for it.

    public boolean print(PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintRequestAttributeSet attr, boolean interactive, PrintService service)

    also look at getPrintable(...) method in JTable, and the javax.swing.TablePrintable class. You will have to do some custom printing code, but TablePrintable is a good start. There is a print() method that takes a pageIndex, and you could do something very much like that, but don't print the header and footer on every page.