Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Problem Printing from Within Java

 
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am running Eclipse Luna Service Release 2 (4.4.2) on a Mac under OS X Yosemite version 10.10.5, Java  and Postgres 9.4.
Can read from the database, but the problem is in printing on a printer from within Java.  The following code is intended to pass the line to be printed to the method  It does fill up the array of textLines.

… The following code is adapted from https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/2d/printing/examples/PaginationExample.java   The discussion of PaginationExample.java is at https://docs.oracle.com/javase/tutorial/2d/printing/set.html  All the textLines in the array can be printed (via traces) on the Eclipse console.  Then the Print dialog appears.  But after Print is selected on the Print Dialog the print lines are not printed and then the program gracefully ends.

If is used, it produces compile error:   Cannot use this in a static context.  – which makes sense, but how do I get it to directly display the PrintDialog, which is implemented code?  The code in PaginationExample is implemented and an intermediary print window with a simple print button is used to display the PrintDialog.  (- this I would not like to include.)  Also, I have no listener.

Thanks for help.  This one really has me stumped.

 I used the following line instead:
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all don't catch exceptions and then do nothing. If an exception is caught at the very least you should print a message and it normally helps if you dump the stack trace. If you don't do anything you won't know something has gone wrong unless your program crashes or exhibits unexpected behaviour and even then you won't know what has caused the problem.

If
job.setPrintable(this)
is used, it produces compile error:  Cannot use this in a static context.

'this' should be the object that renders your print so the line you have following this one is correct.

Have you tried putting System.out.println()  statements in the print method to see what is being rendered for printing.
 
David Ellis Rogers
Ranch Hand
Posts: 58
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved.  I was calling the method rather than creating the class.  Stupid error which I have been guilty of before.
 
Does this tiny ad smell okay to you?
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic