GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes How to print something that is not set initially Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to print something that is not set initially" Watch "How to print something that is not set initially" New topic
Author

How to print something that is not set initially

Khoa Nguyen
Greenhorn

Joined: Aug 08, 2007
Posts: 5
Basically I need to make a program that will print out the animal letters that the user enters into a textbox. I don't know how many letters will be entered so I need to get it after the button has been pressed to define the animals[]. But this doesn't work, the print dialog box opens and nothing appears. Yet if I specify that animals was String[] animals = new String[5] at the beginning, I will get 5 pages in the print preview. How can I get this to show without specifying it ahead of time? thanks for any help, I've been stuck on this for days.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Can you post an SSCCE that shows the problem? Because I've created my own little SSCCE and it prints out what I expect.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Khoa Nguyen
Greenhorn

Joined: Aug 08, 2007
Posts: 5
Ok, so here is a working example. when I type in "cat, dog, cow" and press printer, I see that nothing has happened in the print preview. There should be 3 pages with cat dog and cow on them. I'm not sure what's going on?

Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Hi

I think its because you are creating a new instance of BillPrinter and passing it to setPrintable : printJob.setPrintable(new BillPrinter());

Instead this you should pass this reference to setPrintable: printJob.setPrintable(this);


Piyush
Khoa Nguyen
Greenhorn

Joined: Aug 08, 2007
Posts: 5
that did it. Thanks
 
GeeCON Prague 2014
 
subject: How to print something that is not set initially