Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Print Preview for JTable  RSS feed

 
John Astralidis
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a junior Java developer and I want to build a class that takes a JTable and previews on screen how it will be printed on the default printer. This is what we use to call as "Print Preview", just like MS Word, Excel, etc.

As we already know Java does not support this functionality out-of-the-box.

Based on some examples I've found googling I built two classes. The first one TestPreview.java justs shows the JTable and the second one PrintPreview.java previews how the JTable will be printed on the printer.

I have two buttons to go through the pages, "PREV" and "NEXT" and "Print' button to print the JTable. My problem is that when my JTable has too many rows and spans in more than one page PrintPreview does not work. It shows the same page again and again. Also, it does not show the entire JTable data, but only some of them and I can't figure out why.

Please help.

Below is my two classes.

TestPreview.java



PrintPreview.java



Below are my screenshots.

testFrame.JPG
[Thumbnail for testFrame.JPG]
printPreview-1.JPG
[Thumbnail for printPreview-1.JPG]
printPreview-2.JPG
[Thumbnail for printPreview-2.JPG]
 
K. Tsang
Bartender
Posts: 3628
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

So what you want to do is ... pagination in printing mode?
 
John Astralidis
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Sir.

Yes, this is the exact definition.
 
K. Tsang
Bartender
Posts: 3628
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well to start off, you should use/ work with a JTable model. If you google a bit, you should find some sample code. Surely not every one of them would work or suit your needs but would give you an idea.

I found this that looks alright.

Not sure if your app only for printing, if not, then you probably want a factory or condition to use the paging table model or not.
 
John Astralidis
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Sir for your kind help. That was really helpful at a first glance and Im gonna read it thorougly.

Please take a look at my new thread here if you don't mind. http://www.coderanch.com/t/632240/java/java/print-image-original-size#2895411
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!