Printing user's entry.

Hi guys
I am trying to print the user's entry from a JTextField. But when I pass it to the print method, all i get is a NULL value. Can anyone point me my mistake ? I'd appreciate it :)
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {
        entry = txtEntry.getText().trim();
        // Get the rep of the current printer & print job
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        // Build a book containing pair of page painters (Printables)
        // and PageFormats. This example has a single page.
        Book book = new Book();
        book.append(new Printing(), new PageFormat());
        // Set the obj to be printed (book) into PrinterJob.
        printerJob.setPageable(book);
        // Show print dialog to user.
        boolean doPrint = printerJob.printDialog();
        if (doPrint)
            try
                printerJob.print();
            catch (PrinterException e)
                JOptionPane.showMessageDialog(null, "Unable to print + Error : "
                        + e);
            catch (NullPointerException e)
                JOptionPane.showMessageDialog(null, "Unable to print + Error : "
                        + e);
public int print(Graphics g, PageFormat format, int pageIndex)
        // Java 2D
        Graphics2D g2d = (Graphics2D) g;
        // Move origin from the corner of paper to corner of imageable area
        g2d.translate(format.getImageableX(), format.getImageableY());
        // Perform rendering of text
        g.drawString("Entry : " + entry, 5, 10);
        // Set text colour
        g2d.setPaint(Color.BLACK);
    }

This is the current code I am trying to work out now. If I do get this done I will be trying to get it to print an array instead due to the nature of my project :)
import java.awt.*;
import java.awt.print.*;
import javax.swing.*;
import java.awt.event.*;
public class PrintingTest extends javax.swing.JFrame implements Printable{
    JPanel mainPanel = new JPanel();
    JTextField txtTest = new JTextField("Write something here :D");
    /** Creates new form PrintingTest */
    public PrintingTest() {
        displayPanel();
    public void displayPanel()
        JButton btnTest = new JButton("Test !");
        mainPanel.add(txtTest);
        mainPanel.add(btnTest);
        btnTest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTestActionPerformed(evt);
        this.add(mainPanel);
        mainPanel.setSize(400,200);
        mainPanel.setBackground(Color.YELLOW);
    private void btnTestActionPerformed(java.awt.event.ActionEvent evt)
        // Get the rep of the current printer & print job
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        // Page formating before printing
        PageFormat format = new PageFormat();
        format = printerJob.pageDialog(format);
        // Build a book containing pair of page painters (Printables)
        // and PageFormats. This example has a single page.
        Book book = new Book();
        book.append(new PrintingTest(), format);
        // Set the obj to be printed (book) into PrinterJob.
        printerJob.setPageable(book);
        // Show print dialog to user.
        boolean doPrint = printerJob.printDialog();
        if (doPrint)
            try
                printerJob.print();
            catch (PrinterException e)
                JOptionPane.showMessageDialog(null, "Unable to print + Error : "
                        + e);
    public int print(Graphics g, PageFormat format, int pageIndex)
        String entry = txtTest.getText().trim();
        // Java 2D
        Graphics2D g2d = (Graphics2D) g;
        // Move origin from the corner of paper to corner of imageable area
        g2d.translate(format.getImageableX(), format.getImageableY());
        // Perform rendering of text
        g.drawString("What is going on ?" , 5, 10);
        g.drawString(entry , 5, 20);
        // Set text colour
        g2d.setPaint(Color.BLACK);
        return Printable.PAGE_EXISTS;
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PrintingTest().setVisible(true);
}

Similar Messages

  • Printer User Code

    I use a network printer that requires user codes. I have been unable to find where I can enter this code on my mac in order to print to network printer. Any suggestions?

    There are two ways you can achieve this. One is to use Presets and the other is to use the CUPS web interface.
    With regards to the User Codes, if a user will always be using the same code and they have the only user account of the Mac they use, then the CUPS interface would be better as you can set the code as a default (and b&w printing for that matter). But if a user has different user codes, or they are not the only user on a particular Mac, then the Presets could be a better option.
    To create a Preset, select to print a document and with the print dialog open, set the user code in the appropriate menu. Then click on the Presets drop menu (located under the Printer name) and select Save As. Give an identifiable name and select it for this printer only and then OK. Now when you print you can select this Preset and the user code fields will be correctly entered.
    You could take this a step further and save the b&w setting with this preset. Or you could make two presets, both with the same user code but one as colour and the other as b&w.
    If you wanted to make the settings default rather than use Presets then you can open the CUPS web page (http://127.0.0.1:631/printers/) in Safari. This will show the installed print queues. Select the Lanier queue, this will show another page that will have a Maintenance and Administration drop menu. Via the Administration drop menu, select Set Default Options. With the next page that appear select General and then scroll through the listed options until you see the User Code entry. Set your number and then if you wanted to scroll through to the Colour setting you can also set it to B&W. With these set, scroll all the way to the bottom and click Set Default Options. If prompted, enter your Admin name and password to save the change. Now you can exit Safari and test your print settings.

  • Check the user's entry from query selection screen

    Hi,
    Is there a way to check the user's entry at the selection screen? I created an exit variable and did some code to default a date to the selection screen. What if the user enters some other date, and I would want to check the value of this entry, where would I do this?
    Thanks,
    RT

    RT,
    This can easily be done. You can read the variable after the user has entered some different value.
    I_STEP = 2.
    Read table i_t_var_range with key vnam =<your variable name >
    Hope it helps.
    Thx,
    Soumya

  • Printing User Name on view

    Hi All,
    I need some information in web dynpro. not in portal.
    I have code here
    IWDClientUser user = WDClientUser.getCurrentUser();
    IWDAbstractButton button;
    button = (IWDAbstractButton)view.getElement("User");
    i want to print user information on button in a View.
    I tryied my best to print but i don't find any printing elements .
    thanks
    Ravi

    Hi Ravi,
    This is just for some fun but I am sure I answer your  question completely and your problem must have got solved 100% and if I am right then there is a option to allot 10 points for the solved queries
    Ok its fine atleast mark the question as answered.
    Regards
    Sid

  • Printed User Guide

    Does anyone offer a printed user guide for the 8330?
    Solved!
    Go to Solution.

    Try downloading from here
    If someone has been helpful please consider giving them kudos by clicking the star to the left of their post.
    Remember to resolve your thread by clicking Accepted Solution.

  • PRINTER USER NAME AND PASSWORD

    Pproduct:  HP Photosmart Premium c309a      OS: Windows 7   Error Message: Need printer's User Name and Password
    Trying to print from my iPhone I am asked for printer User Name and Password.  Where do I find them?

    I checked the link, I only see B210a, C310a, C510a printers but not C309a. But at least now you know which printers would be capable of eprint feature.
    Kawaii would mean cute (in Japanese language)
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Cheers!
    * If this post has helped you, the White Kudos star on the left is a great way to say thanks!
    * Please mark Accept As Solution if it solves your problem so other users can benefit as well.

  • How can I ge a printed user manual for Photoshop Elements 12

    Is a printed user manual for photoshop elements 12 available?

    Hi venice50,
    I've moved your discussion to the Photoshop Elements forum. Please see this page: Photoshop Elements Learn & Support.
    Click the Previous versions links at the bottom of the Help and Tutorials list to find links to PDF versions of Photoshop Elements 12 Help. I don't know whether there are printed versions available, but the smart folks who visit this forum regularly should be able to point you to them, if they exist.
    Best,
    Sara

  • User exit ZXRSRU02 to get user's entry

    Hi,
    Will this code work to get get the user's entry and start processing it from program ZXRSRU02:
    Data: L_S_CHANM TYPE RRKE_S_CHANM.
    CASE I_S_RKB1D_INFOCUBE.
    WHEN 'DEMOCUBE'.
    L_S_CHANM-CHANM = 'PRODUCT'.
    L_S_CHANM-MODE = RRKE_C_MODE-READ.
    APPEND L_S_CHANM TO E_T_CHANM.
    L_S_CHANM-CHANM = 'PRICE_TP'.
    L_S_CHANM-MODE = RRKE_C_MODE-NO-SELECTION.
    APPEND L_S_CHANM TO E_T_CHANM.
    APPEND 'ACT_PRICE' TO E_T_KYFNM.
    APPEND 'QUANTITY' TO E_T_KYFNM.
    ENDCASE.
    Will this code allow me to get the user's entry from the selection screen?
    Tahnks,
    RT

    Hi,
    Yes your'e correct about the requirement.
    Here are the links to what I have completed so far but I would get the value with 6 numbers similar to 736,278, for example. I am asking for more time to resolve this 6 number results but was told to use the program ZXRSRU02 and make use of virtual char. I would think to make use of Virtual Char is more complicated and more coding is require.
    Re: How to create cutsomer exit variable to a replacement path variable
    Re: Compute number of days using user's entry date as an operand
    Re: Check the user's entry from query selection screen
    Thanks,
    RT
    Message was edited by: Rob  Thomas

  • Printed User Guide for Elements 6 for Mac

    While the very useful downloaded pdf version from Adobe is in color, I discovered that the images in the printed guide from Adobe are in black and white, and are not of the same quality.

    I have the printed Users Guide for Windows PS Elements 6 and it is also in black and white. To me the quality of the black and white images in the Windows book is OK: however the absence of color is very significant for some images. I have not seen the book for the Mac so I can't comment on image quality.
    I can only suggest using a combination of the book plus the PDF file images displayed on screen.

  • [Ask] Print user defined Field

    Hi guys, need some help here....
    Can I print user defined field? If it can, how?
    thx guys...I really need it

    hi yoga,
    Yes you can display user defined field in PLD.
    create a database field,select table name and
    select column type you can see user defined field
    in name(For example :U_doctype) and its description.
    Jeyakanthan

  • Can I get a printed user's manual?

    Can I get a printed user's manual for 4S iphone?

    No, other the than the quick start booklet that came with the device, all manuals are electronic (and for the most part based on the version of iOS rather than the specific device model). In addition to the PDF Kappy linked, they are avilable as iBooks (free download) and as a website: http://help.apple.com/iphone/7/.

  • Printed User Manual

    Is it possible to order a Printed User Manaul for the 8830?

    Not that I am aware of. You can download the manuals in PDF format.

  • Printing user validation errors from .php file back onto a form

    Hey all. I have written a simple contact form with the extention .php. It includes the php validation and the form inputs on one page. If the input does not validate, a warning in red is printed at the top of the form after the user pushes submit. When I cut and paste the php validation code into a seperate file, the validation errors print on a blank screen. What I want is to have the same results with a seperate php file as I do when I include the php code on the form. (print errors from the seperate php validation file back onto the form).  Thanks for taking a look
    <h1><span class="bodyheader1">Contact </span><span class="bodyheader2">Us</span></h1>
        <p class="subheading">Tell us what's on your mind:</p>
        <?php
        if(isset($_POST['send_comment']))
            //Validating the comment field
            //checking if a first_name field has been entered
            if($_POST['first_name'] != "")
                //Saitizing first_name with a filter
                $_POST['first_name'] = filter_var($_POST['first_name'], FILTER_SANITIZE_STRING);
                //Checking for no input
                if($_POST['first_name'] == "")
                    //If no input, return error message
                    $errors .='Please enter a valid first name.<br/>';
            else
                //Error message
                $errors .='Please enter your first name.<br/>';
            //Validating the last_name field
            //checking if last_name has been entered
            if($_POST['last_name'] != "")
                //Saitizing last_name with a filter
                $_POST['last_name'] = filter_var($_POST['last_name'], FILTER_SANITIZE_STRING);
                //Checking for no input
                if($_POST['last_name'] == "")
                    //If no input, return error message
                    $errors .='Please enter a valid last name.<br/>';
            else
                //Error message
                $errors .='Please enter your last name.<br/>';
            if($_POST['email'] != "")
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
                if (!filter_var($email, FILTER_VALIDATE_EMAIL))
                    $errors .= "$email is not a valid email address.<br/>";
            else
                $errors .= 'Please enter your email address.<br/>';
            //Validating the comment field
            //checking if a comment has been entered
            if($_POST['comment'] != "")
                //Saitizing comment with a filter
                $_POST['comment'] = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
                //Checking for no input
                if($_POST['comment'] == "")
                    //If no input, return error message
                    $errors .='Please enter a comment.<br/>';
            else
                //Error message
                $errors .='Please enter a comment.<br/>';
            if(!$errors)
                $mail_to = '[email protected]';
                $subject = 'Contact form ' . $_POST['first_name'];
                $message = 'First Name: ' . $_POST['first_name'] . "\n";
                $message .= 'Last Name: ' . $_POST['last_name'] . "\n";
                $message .= 'Email: ' . $_POST['email'] . "\n";
                $message .= 'Comment: ' . $_POST['comment'] . "\n\n";
                mail($mail_to, $subject, $message);
                echo "<script>document.location.href='thankyou.html'</script>";
            else
                echo '<div style="color: red">' . $errors . '<br/></div>';
    ?>
    *All fields are required<br />
    <br />
        <form name="contact" method="post" action="contact.php">
            <p>First Name: <br />
              <input name="first_name" type="text" value="<?php echo $_POST['first_name']; ?>" size="30" maxlength="50" /><br />
              <br />
              Last Name: <br />
              <input name="last_name" type="text" value="<?php echo $_POST['last_name']; ?>" size="30" maxlength="50" /><br />
              <br />
              E-mail: <br />
              <input name="email" type="text" value="<?php echo $_POST['email']; ?>" size="40" maxlength="200" /><br />
              <br />
              Comment: <br />
              <textarea name="comment" rows="5" cols="50"><?php echo $_POST['comment'];?></textarea>
              <br />
             </p>
          <p><input type="submit" name="send_comment" />
          </p>
        </form>

    You want the form to submit its results to a separate file which processes the data.  If this separate file finds errors, you want it to return control to the form page which would a) display the error messages, and b) populate the fields with the data entered?
    If that's the case, then the processing file would have to send the errors and the data back to the form page either as a) URL variables, b) a cookie, or c) entries in a database.
    Does that help?

  • Create a variable for user input entry to act as i/p to anothr variable

    Hi,
    I have a requirement in my report where i have two variables one is user entry called "A" the a other user exit "B" and the query is based on an ods.
    <b>
    Scenario:</b> If the user were to enter a string  XXX in A, i need to do a search on certain columns in ODS and store the corresponding keys (single column) in an internal table and the internal table column will act as multiple single values for variable B .
    <b>Questions:</b>
    1. How to get  the value entered in A.(so i can do select statement on ODS table).
    2. In the select statement we need to specify FROM table, so what would the ods table name be.
    3. How to store the values from the select statement into the internal table.
    4.How to populate the values in internal table into variable B.
    5.Once all this is done i need to reset the variable A to empty.
    p.s: ABAP code for any of the following would be highly appreciated.

    hi Karthik,
    1.  you can try
    LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
                  WHERE VNAM = 'varA'.
                  l_var = LOC_VAR_RANGE-LOW.
    2. ods table name = /bic/a[odsname]00 or /bi0/a[odsname]00
    3. use select .... from... into table ...
    4. loop at that internal table and populate as sample code
    5. try to create a RKF with restriction to variable A, and hide this keyfigure,
        not use in reporting.
    hope this helps.
    Populating material numbers from a table to customer exit bex variable
    tables : /bic/azods00.
    DATA: it_ods like /bic/azods00 occurs 0 with header line.
    CLEAR L_S_RANGE.
    WHEN 'varB'.
        IF I_STEP = 2.
          LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
                  WHERE VNAM = 'varA'.
                  l_odsfield = LOC_VAR_RANGE-LOW.
    SELECT * FROM /bi INTO TABLE it_ods
    WHERE odsfield = l_odsfield.
    loop at it_ods.
    L_S_RANGE-LOW = it_ods-fieldselected.
    L_S_RANGE-SIGN = 'I'.
    L_S_RANGE-OPT = 'EQ'.
    APPEND L_S_RANGE TO E_T_RANGE.
    endloop.
          ENDLOOP.

  • Print User name at bottom of the page

    Used to be in Macintosh Manager, but has anyone found a way to be able to print a user's name at the bottom of each page they print.

    No automated way, although you could add a textbox to the bottom of your master slide(s)

Maybe you are looking for

  • Apple TV Air Tunes error -15000

    Since I have installed iTunes 8 my apple tv has been acting very strange. Has anyone else noticed? It seems to be slower, it has crashed once or twice, the last time it crashed It blew away all my content. I had to re-sync my photo's etc.. But my mai

  • Payment terms with 50% of value of the invoice  in diferent dates

    Hi Sap Gurus, I would like to request your help for teh following issue. We need to use a SAP condition that 50% of the invoice is payd immediatly and 50% in 30 days How can do that?

  • Schedule Snapshots Rotation

    Hello, I have two Hyper-V servers running Replica feature, it is working great, but it only protects me from hardware failure. Now I want to have snapshots enabled for quick rollbacks (and full backups for more restoring options, but that's for later

  • Gnome 3.16 resume from suspend weird issues

    After upgrade to gnome 3.16 with gnome-shell 3.16.1-2  and gdm 3.16.1.1-1, also with previous 3.16 versions, after I suspend to ram for some time and resume from it, the gdm window freezes and cannot input. After some tty switching using ctrl+alt+f1/

  • IOS 6 Bluetooth Connectivity

    Having just bought the iphone 5 i have tried to pair the bluetooth with my car (2008 Ford Mondeo).  It will find 'Ford Audio' but will not pair. I get the error message saying that i should ensure i am close to the device and that it is switched on.