Solved

Printing a JTable in JAVA

Posted on 2007-12-03
7
1,767 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now