Solved

Printing a JTable in JAVA

Posted on 2007-12-03
7
1,771 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:sandeep1984
7 Comments
 
LVL 9

Assisted Solution

by:ysnky
ysnky earned 100 total points
ID: 20401210
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 200 total points
ID: 20401232
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 20402368
0
 
LVL 37

Expert Comment

by:zzynx
ID: 20418042
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)
0
 
LVL 9

Expert Comment

by:ysnky
ID: 20581871
i think the point must be splitted.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
github account with ecipse 1 48
javap not working 8 46
Configure a Bean in an XML file 4 33
mysql jsp example issue 32 38
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question