Meaningless Drivel is fun!
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing JTable" Watch "Printing JTable" New topic

Printing JTable

Chad Risch

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

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!

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

Joined: Sep 22, 2001
Posts: 2591

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
for more help.
- Manish
I agree. Here's the link:
subject: Printing JTable
jQuery in Action, 3rd edition