Solved

Printing a JTable in JAVA

Posted on 2007-12-03
7
1,776 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

739 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