File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Printing JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing JTable" Watch "Printing JTable" New topic
Author

Printing JTable

Chad Risch
Greenhorn

Joined: Aug 04, 2003
Posts: 3
Hello, I'm trying to print out a JTable but I'm having some problems. Currently, my table is spanning too far width wise and so columns are being printed on seperate pages when I want them to all be on the same page. It is a fairly wide table, but it all fits on my screen, so I would like to shrink the table to whatever size necessary to get it to fit on the page. I'm only concerned with the width fitting to the page. I don't mind having multiple pages due to having many rows. Can anyone one guide me in the right direction? If possibly, I'd appreciate examples, but if that isn't possibly, I'll take whatever anyone can offer. Thanks in advance.
Note: auto resizing is already in place. I just want to shrink the table somehow when it gets sent from the screen to the printed page.
[ March 12, 2004: Message edited by: irncty99 ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

"irncty99" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

Try this -
double pageWidth = pageFormat.getImageableWidth();
double tableWidth = (double) this.getColumnModel().getTotalColumnWidth();
double scale = 1;
if (tableWidth >= pageWidth) {
scale = pageWidth / tableWidth;
}
hould work. Refer to
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html
for more help.
- Manish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing JTable
 
Similar Threads
JTable
Swing problem with JTable
jtable
JTable-JScrollPane
JTable