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

Run Windows command from flash

xml actionscript-3 flash-cs5

Is it possible to delete the contents of a local XML file using a Flash CS5 document being played on the desktop and using AS3?

Multiple controls with same bindings in single xaml

c# wpf xaml treeview

I have a xaml with a TabControl with two tabs. Each of the TabItems has a treeview which has exactly the same code. The bindings, VM etc are exactly same. They work of different data which is handl...