Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing in swing  RSS feed

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hola ranchers.
I am developing a Swing application, and the main form contains *as usual* text fields combo boxes..... and a button called 'Print'.
I want when I filled these fields and press Print button, it should print a paper (ofcourse using the printer) containing these information.
How to perform this task using swing??
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Tutorial: Printing
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean, I want to print the information that I have entered into the text fields into a paper using the printer.
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the printing tutorial told you, what, how to arrange flowers?
This example from the tutorial is about as simple as it gets (excluding the ugly drawShapes method).
 
Paul Bailey
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, but this line doens't work for me:
-----
printJob.setPrintable(this);
--------
It says
---------
edu/yak/Main.java:548: cannot resolve symbol
symbol : method setPrintable (edu.yak.Main.ScheduleJPanel)
location: class java.awt.print.PrinterJob
printJob.setPrintable(this);
^
-----------
You might notice that I am using an inner class here, but that inner class is a JPanel. It doesn't work if I use printJob.setPrintable(new JPanel()) either!
darn example!
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Bailey:
edu/yak/Main.java:548: cannot resolve symbol
symbol : method setPrintable (edu.yak.Main.ScheduleJPanel)
location: class java.awt.print.PrinterJob
printJob.setPrintable(this);

I just compiled the example ok. May be if you are in an inner class perhaps it has problems accessing the printJob variable. From an inner class you can only access final variables from the enclosing class. I noticed that the example implemented ActionListener so does not need to use inner classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!