This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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.
 
Something must be done about this. Let's start by reading this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic