in relation to this thread I have a question if someone to know if is possible to override/change larger font (Font Type, Size, Color) for MessageFormat headerFormat comings with JTable.PrintMode or I must paint g2.drawString(“my header/footer”) and JTable#print() separatelly
Share
As everybody already mentioned (while I was relaxing in vacation 🙂 – TablePrintable is tightly knitted for secrecy, no way to subclass, no way to configure the header/footer printing. The only option to hook is to wrap the table’s default printable, let it do its work without header/footer and take over the header/footer printing oneself.
The problem with the snippets shown so far is that they dont play nicely with multi-page – as known and mentioned by all authors, of course – because the default printable thinks there are no headers/footers and freely uses the space required by them. Not surprisingly 🙂
So the question is: is there a way to make to default not print into the region of the header/footer? And yeah, it is: double-wopper (ehh .. wrapper) is the answer – make the default printable believe it has less printable space by wrapping the given pageFormat into one that returns a adjusted getImageableHeight/Y. Something like:
Then use in the printable wrapper (footer has to be done similarly):
And at the end return that from table’s getPrintable, like:
printHeader/Footer can be implemented to do whatever is required.
At the end of the day: the answer to the question “do I need to call g.drawString(…)” still is “Yes”. But at least it’s safely outside of the table itself 🙂