JTable appearing as box when printing

I have the following method which creates a JTable then prints it out by its appearing as a rectangle no the page with the header and footer.

public void printModules(){
    MessageFormat header = new MessageFormat("Modules " + new Date());
    MessageFormat footer = new MessageFormat("Created by Assignments Database");
    try {
        JTable jtModules = new JTable(new ModulesTableModel(Controller.getInstance().getModules()));
        jtModules.setShowHorizontalLines(true);
        jtModules.setShowVerticalLines(true);
        jtModules.setShowGrid(true);

        boolean complete = jtModules.print(JTable.PrintMode.NORMAL, header, footer, true, null, false, null);

        if(complete){
            System.out.println("Printed");
        } else{
            System.out.println("Printing Cancelled");
        }
    } catch (PrinterException e) {
        e.printStackTrace();
    }
}

What else is wrong? There is data in the table as one that is created from the same data is showing in one of the panels.

In my abstract table model I have implemented the following methods:

  • Constructor
  • getRowCount
  • getColumnCount
  • getValueAt
  • getColumnNames

Is there any other methods that need to be created?

Answers


JTable has very reduced support for printing, there are some descriptions about printing in the tutorials about JTable (inc. code example) and Printing


You need to display the table in order to print it, so add it to a JFrame, then frame.setVisible(true); then frame.setVisible(false); This will make it print.


Need Your Help

How can I see all the functions that belong to 'math.h' in c++?

c++ eclipse netbeans ide

I am learning C++. In Java I could use 'Math.' and then Eclipse would show me all the methods available for the math class. I have tried both Eclipse and Netbeans to find this feature. Control + Sp...

iPhone - application being ejected

iphone iphone-sdk-3.0 ipad

I have an application that is being ejected by iPhone OS for "low memory".