method to print the table.
public static void PrintTable(JTable table,String title) {
try {
MessageFormat headerFormat = new MessageFormat(title);
MessageFormat footerFormat = new MessageFormat("{0}");
boolean complete = table.print(JTable.PrintMode.FIT_WIDTH,headerFormat, footerFormat);
if (complete) {
JOptionPane.showMessageDialog(null, "Printing Completed.");
}else {
JOptionPane.showMessageDialog(null, "Printing Canceled !");
}
} catch (PrinterException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null,e);
}
}
The application output table column seems like this (Correct).
| Address |
:--------------------------
| Kathmandu Nepal
| Kirtipur 5 Kathmandu Nepal |
| Baneswor 10 Kathmandu Nepal |
| Balkhu 2 Kathmandu Nepal |
But a hard copy of print is like this:(Missing space between some words).
| Address |
:------------------------
| Kathmandu Nepal
| Kirtipur5KathmanduNepal |
| Baneswor10KathmanduNepal |
| Balkhu2KathmanduNepal |
How to overcome this problem? I googled but did not found the related solution.
This happened due to the 'Microsoft Sans Serif' font for JTable. I changed the font to 'Tahoma'. It works.