Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Printing Setup

  1. #1
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Printing Setup

    Hi again. in this part of my program the user has the option to print whats been generated in the text area by pressing a button. i have got it to be able to print and work my only concern is the format of the page and how to set it up the way i want it as a default so the user doesnt have to change it each time. is there a way to edit the print() methods default setup? thanks.


    Java Code:
      private void hardPrintActionPerformed(java.awt.event.ActionEvent evt) {                                          
    
    
            try {
                boolean complete = printOut.print();
                if (complete) {
    
                    printed itemloader = new printed();
                    itemloader.setVisible(true);
    
              
    
                } else {
               
                }
            } catch (PrinterException pe) {
             
            }
    
    
        }

  2. #2
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    Nobody has experience with this situation? i could really use some feedback.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Printing Setup

    There's another print( ... ) method defined in the JComponent class (the parent of the JTextArea class) that allows you not to show a print dialog ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

  5. #5
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    Quote Originally Posted by JosAH View Post
    There's another print( ... ) method defined in the JComponent class (the parent of the JTextArea class) that allows you not to show a print dialog ...

    kind regards,

    Jos
    but can you preset margins within your code with that?

  6. #6
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    Can someone please tell me why my page i print starts printing at about half way down until the end of the page and thats it? i want it to start at the top of the page. perferably .25in top margin. is there something in my code that is causing this? thanks for your time. your advice is greatly appreciated.

    Java Code:
    PrinterJob pj = PrinterJob.getPrinterJob();   
                  
                PageFormat pf = pj.defaultPage();   
                Paper paper = new Paper();   
                double margin = .25;    
                paper.setImageableArea(margin, margin, paper.getWidth() -margin * 2,
                        paper.getHeight()   
                    - margin * 2);   
                pf.setPaper(paper);   
      
                pj.setPrintable(new MyPrintable(), pf);   
                if (pj.printDialog()) {   
                  try {   
                    pj.print();   
                  } catch (PrinterException pp) {   
                    System.out.println(pp);   
                  }   
                }   
      
    
    
    
    
    
    
    
            // TODO add your handling code here:
        }                                         
    
        /**
         * @param args the command line arguments
         */
    class MyPrintable implements Printable {   
    
           
            public int print(Graphics g, PageFormat pf, int pageIndex) {   
                if (pageIndex != 0)   
                  return NO_SUCH_PAGE;   
            Graphics2D g2 = (Graphics2D) g;   
            g2.translate(pf.getImageableX(), pf.getImageableY());   
            Rectangle componentBounds = printOut.getBounds(null);   
            g2.translate(-componentBounds.x, -componentBounds.y);   
            g2.scale(1, 1);   
            boolean wasBuffered = printOut.isDoubleBuffered();   
            printOut.paint(g2);   
            printOut.setDoubleBuffered(wasBuffered);   
            return PAGE_EXISTS;   
            }   
        }

  7. #7
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    no one as ever had this problem before? id really appreciate some help. i can't figure out why it starts halfway down the page and then doesnt even carry on to the next page to print the rest of it.

  8. #8
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    ok i added this into my MyPrintable class and now it starts printing in the correct spot. But still only prints one page. do i have to set up a book to do more than one page?
    Java Code:
    printOut.setBounds(0, 0, printOut.getWidth(), printOut.getHeight());

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Printing Setup

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    hi db, thanks for your response. im getting all my data from the jtextarea "printOut", how would i incorporate that instead of using textLines from that example you gave me. is there a way to say after reach a certain height of the paper to make that a new page? im very confused with this. Should i be using book or paper? does it make a difference?

  11. #11
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    i have it calculating how many pages my textarea will need to print all the data but how while i tell it to print after a certain height make another page? like using that pagebreak thing you referred me to. im not counting lines im counting the height of the paper.
    Java Code:
    int height = printOut.getHeight();
     paper.setSize(612,792);
    ......
    ......
      int numpages =1;
            if (height >792) {
                for (int i = 792; i < height;) {
                    numpages = numpages+1;
                    i= i +792;
                }
            }
            System.out.println("numpages ="+numpages);
          bk.append(new MyPrintable(), pf,numpages);

  12. #12
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    db, do you know how to solve this situation without using drawString? but instead to just simply print out the textarea without using the print() statement? the print() statement works fine but the problem with that is that you have to set the margins each time and i keep reading it doesnt support preset margins.

  13. #13
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Printing Setup

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  14. #14
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    i posted it there because no one seemed to know the what i could do on this forum website and i cant find out how to do this anywhere without using the drawstring or the print() method with only default margins.

  15. #15
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    im not trying to offend you, im just scrambling for help because i need to get this done. sorry.

  16. #16
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Printing Setup

    Quote Originally Posted by gbonecapone View Post
    im not trying to offend you, im just scrambling for help because i need to get this done. sorry.
    Unfortunately now you've basically made it so people will be far less inclined to help you, if they know the answer. And you should realize that when people are not answering that perhaps they simply don't actually -know- the answer; in stead of spamming please please please and spamming to different forums, take the hint that you are perhaps going to have to do this all on your own and in case you cannot, you'll have to admit defeat and do it a more ugly way that you can make to work.

    I can't imagine there are many people in the world today that use the Java printing API for anything to be honest - if they do it will probably be in the simplest way possible. I'd rather make my application output stuff in a common format (PDF for example) which will allow people to print it using an existing tool most appropriate for it.

  17. #17
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    thanks im sorry. its just frustrating not being able to do something that seems like it would be so simple. you guys are damn near geniuses so i assumed a lot of people would probably know what im trying to do since im only 2 months into java programming. i had it just using print() and it pop up that dialog box but the engineers, at my work, using the program told me they dont want to have to set the margins everytime because they didnt have to in the truebasic program i am converting this from. i also didnt realize the three forums i posted on consisted of all the same same people. i figured it was just a different website. why dont people use Java printing API? because its frustrating?

  18. #18
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Printing Setup

    Because not many people will today be building applications that need it. Java isn't exactly a platform used for client-side application development, its more applied server-side.

    And of the subset of people that do build client-side applications, only a subset will require actual printing features.

  19. #19
    gbonecapone is offline Member
    Join Date
    May 2013
    Posts
    68
    Blog Entries
    1
    Rep Power
    0

    Default Re: Printing Setup

    My job decided for me to use java because the truebasic program wouldnt work on windows 7 64bit. it basically takes inputs to creat a timing screw, send a data file to the mazak and printout a hardcopy to put in the job folder.do you think that java wasnt the right choice? this is what it looks like. and do you think it will be easier or possible to have the program take the textarea content write it to a text file and then print out the text file right from the program?
    Printing Setup-prog.png

  20. #20
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Printing Setup

    It always pains me to see people working under horribly broken IT management.

    Unfortunately I too am not the one to answer that question since I have never and never will build a Java program which will require printing. I focus on creating digital files only (PDF, Word, whatever) and if you want a hard copy - print it yourself!

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 12-26-2011, 04:52 PM
  2. Replies: 9
    Last Post: 08-19-2011, 01:59 AM
  3. printing string backwards and printing every other
    By droidus in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 10:17 AM
  4. Setup creator...
    By SagarMohril in forum New To Java
    Replies: 0
    Last Post: 01-07-2011, 02:11 PM
  5. Setup
    By Mir in forum New To Java
    Replies: 9
    Last Post: 06-27-2008, 12:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •