Displaying Print Dialog

Hi,

I would like to display a print dialog (prss Print button from JPanel).  I use the following code:

import java.awt.print.*;

...

PrinterJob job = PrinterJob.getPrinterJob();



The code compiles, but I get this (on the line above) error:

java.lang.NoClassDefFoundError: java/awt/print/PrinterJob
    at com.ignitus.SwitchInventory.SwitchInventorySelect.help_actionPerformed_Interaction1(SwitchInventorySelect.java:124)
    at com.ignitus.SwitchInventory.SwitchInventorySelect.help_actionPerformed(SwitchInventorySelect.java:116)
    at com.ignitus.SwitchInventory.SwitchInventorySelect$SymAction.actionPerformed(SwitchInventorySelect.java:107)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1066)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1101)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:217)
    at java.awt.Component.processMouseEvent(Component.java:2355)
    at java.awt.Component.processEvent(Component.java:2200)
    at java.awt.Container.processEvent(Container.java:904)
    at java.awt.Component.dispatchEventImpl(Component.java:1809)
    at java.awt.Container.dispatchEventImpl(Container.java:949)
    at java.awt.Component.dispatchEvent(Component.java:1741)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1739)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1537)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1453)
    at java.awt.Container.dispatchEventImpl(Container.java:936)
    at java.awt.Window.dispatchEventImpl(Window.java:491)
    at java.awt.Component.dispatchEvent(Component.java:1741)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:81)


Thanks,

Alex.
akoifmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zhongbingCommented:
It's strange, make sure you jdk is correctly installed and the CLASSPATH is correctly configured. Maybe your rt.jar was broken.
0
zhongbingCommented:
maybe the best way is reinstall your JDK.
0
expertmbCommented:
hi,
try this

 void print_actionPerformed(ActionEvent e) {
       PrintJob pj =
                  f.getToolkit().getPrintJob(f, "print1", null);
  }

mb...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

akoifmanAuthor Commented:
Hi,

What is F in
PrintJob pj =
      f.getToolkit().getPrintJob(f, "print1", null);
 

How do I display the print dialog?

Thanks,

Alex.
0
expertmbCommented:
>>What is F in
Frame f = new Frame();

mb...
0
akoifmanAuthor Commented:
Hi,

I need PrinterJob to display the Printer dialog box.  PrintJob does not do it:

Error: C:\nms\com\ignitus\SwitchInventory\Report.java(266): Method printDialog() not found in java.awt.PrintJob

This is the code I am trying to use:

PrinterJob printJob = PrinterJob.getPrinterJob();
            //printJob.setPrintable(this);
            if (printJob.printDialog()) {
                try {
                    printJob.print();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
0
expertmbCommented:
0
heyhey_Commented:
what's your OS / JDK version / Swing version ?
0
vladi21Commented:
My answer:

Java 1.2
7.2.3.2 Print dialog

Typically, an application presents a print dialog to the user when a
print menu item or button is activated. To display this print dialog,
you call @PrinterJob.printDialog@ method. The user's choices in the
dialog are constrained based on the number and format of the pages in
the @Printable@ or @Pageable@ that have been furnished to the
@PrinterJob@.  If the user clicks OK in the print dialog, @printDialog@
returns @true.@  If the user cancels the print dialog, @false@ is
returned, and the print job should be considered abandoned.

---
So if u use Java 1.2 u can find answer here
http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/render.html

also look
http://manning.spindoczine.com/sbe/files/uts2/Chapter22html/Chapter22.htm
http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.