0

How can I automatically print without poping up dialog box or automatically accept print dialog? Here is some of my code:

if ("OUT".equals(rs.getString("empattendance"))) {
    String date  = dft.format(dNow);
    String time = tft.format(dNow);
    textArea.setText(date + "\n" + "\n" + 
              fullname +"\n" +
              "Time In: " + time + "\n" +
              "Status: "+ statusin +
              "\n" +
              "\n" +
              "____________________\n" +
              " Sign by Supervisor");
    try {
        //printing
        Boolean complete = textArea.print();
        if(complete){
        }
        else{
        }
    } catch (PrinterException ex) {
        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    }

and here's the screenshot of the current behaviour.

thanks

YakovL
  • 7,557
  • 12
  • 62
  • 102

1 Answers1

0

When I look at your code I have few thoughts before answer.
1) Do not use String. Better for comparing stuff is Enumerators I believe.
2) If you would like to set text to textArea previously create some method using StringBuilder for example which will be creating the String you would like to set. Joshua Bloch says

Item 15: minimize mutability (...) If a client requires performing expensive multi-stage operations on your class, expose them as primitive methods, or provide a mutable companion class (like StringBuilder for String).


And take a look at this topic for more.
3) To print data from textArea if I were you I would try to use this.

I believe that would help you

Community
  • 1
  • 1