?
Solved

Printing a JTable in JAVA

Posted on 2007-12-03
7
Medium Priority
?
1,784 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 300 total points
ID: 20401210
0
 
LVL 26

Accepted Solution

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

Assisted Solution

by:CEHJ
CEHJ earned 600 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

764 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