• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Printer Class from a JTable

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable that I want to transform into a simple all text report. Essentially I want to have a header, footer and the rows from the table (with a little additional information on each row) listed on however many pages it takes. I can find lots of tutorials on complicated reports with graphics but nothing that is simple text. Can someone point me to such an example? It appears I am perhaps supposed to use JTextComponent but all I can find for that are display tutorials not printer tutorials. TIA.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you consider using iReport instead of doing it all?
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I didn't know about iReport until now, no. I'll look into that. Thanks.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the general idea but cannot find a tutorial or example that does what I want. All the examples assume the data is coming from a database. In my case the data is coming from a JTable. I cannot find anything that shows me how to connect iReports to a JTable. I think I need to set up the report outside of my Java app then use the resulting Jasper file in my app. Can someone point me in the right direction or is this a case of trying to crack an egg with a sledgehammer?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pass values as parameters to iReport from your application if you're not using database (I assumed you do in the first place, my mistake).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe this is all you need

http://docs.oracle.com/javase/tutorial/uiswing/misc/printtable.html
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that looks more like the kind of simple solution I need. However, in looking at the examples and documentation I need to clarify one thing. Am I correct that 'print' is repeatedly called with increasing page numbers (3rd argument) until I return NO_SUCH_PAGE? Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!