Printing a JTable in JAVA

Posted on 2007-12-03
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.

Question by:sandeep1984

Assisted Solution

ysnky earned 100 total points
ID: 20401210
LVL 26

Accepted Solution

ksivananth earned 200 total points
ID: 20401232
LVL 86

Assisted Solution

CEHJ earned 200 total points
ID: 20402368
LVL 37

Expert Comment

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.

     true, unless printing is cancelled by the user
     PrinterException - if an error in the print system causes the job to be aborted
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):


(I link it with the pressing of Ctrl+P in my table)

Expert Comment

ID: 20581871
i think the point must be splitted.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 35
Which non-HTML GUI front end to use with Java? 3 24
Java Eclipse Loop 3 21
What is the use of Forwarding Class in java 1 18
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

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