I have a table called table and its filled with data, I also have a MessageFormat header I want to use as a header to print the JTable this is the MessageFormat:
MessageFormat header = new MessageFormat("Product: "
+ task.getProductName() + " Job: "
+ task.getJobNumber() + " Task: " + task.getTaskID()
);
I want to print 3 lines in the header, one for Product, Job and Task
the way I print this table is like so:
table.print(JTable.PrintMode.FIT_WIDTH, header, null);
I can’t seem to figure out how to print the header in 3 seperate lines, I tried using the \n to make a new line but that doesn’t seem to work.
It’s gonna be long answer (code wise) because the only solution I found was to implement a custom
Printable. Of course I didn’t write the following code myself, I mostly copied the code I extracted from the jdk sources and made some adjustments.Here we are:
This is the way you said you invoke the print method:
where
TablePrintableis the following class (sorry for not being concise here):And here is the result (I hope that’s what you expect):
