Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to print something that is not set initially

 
Khoa Nguyen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post an SSCCE that shows the problem? Because I've created my own little SSCCE and it prints out what I expect.
 
Khoa Nguyen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Khoa Nguyen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that did it. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic