Link to home
Start Free TrialLog in
Avatar of sandeep1984
sandeep1984Flag for India

asked on

Printing a JTable in JAVA

I want to print a JTable which extends DefaultDableModel.
I am using JDK 1.6
The print dialog should show custom options like choosing landscape/portrair modes etc.

Thanks
SOLUTION
Avatar of ysnky
ysnky
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since Java 1.5 the class JTable has a print() method:

public boolean print() throws PrinterException

A convenience method that displays a printing dialog, and then prints this JTable in mode PrintMode.FIT_WIDTH, with no header or footer text. A modal progress dialog, with an abort option, will be shown for the duration of printing.

Returns:
     true, unless printing is cancelled by the user
Throws:
     PrinterException - if an error in the print system causes the job to be aborted
Since:
     1.5
See Also:
     print(JTable.PrintMode, MessageFormat, MessageFormat, boolean, PrintRequestAttributeSet, boolean),  
     getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)

So, this is how I print the tables in my app (Jave 1.5 or higher required):

     myTable.print();

(I link it with the pressing of Ctrl+P in my table)
i think the point must be splitted.