• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Printing in swing

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java Tutorial: Printing
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic