Problem in setting the printer

Hi,
I am new to swings and am trying to print my table using PrintJob class. In this I will get the printer name. So I have to set that as a printer to do the job.
I am able to print by selecting the printer in printDialog but I want to give my printer and I dont want that printDialog box. Plz tell me solution.
As from the docs, i came to know that if we remove printdialog(), it wont show you the dialog box, but its talking the default one, my case is it should take the user input.
Here is my code and working fine.
public void print(String printer){
// In this I have to set printer as the printer to do the job by suppresing the print dialog.
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
pj.setPrintable(this, pf);
if (pj.printDialog()) {
try {
     pj.print();
} catch (Exception e) {
Thanks in advance..
Raj.

import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.io.*;
import java.util.*;
import javax.print.*;
import javax.swing.*;
public class Print_Demo extends JFrame {
    public Print_Demo() {
        initComponents();
    private void initComponents() {
        toolBar = new JToolBar();
        printB = new JButton();
        printerField = new JTextField("Win32 Printer : HP DeskJet 610C");
        panel = new MyPanel();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Print Demo");
        toolBar.setFloatable(false);
        printB.setText("Print");
        printB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                printBActionPerformed(evt);
        toolBar.add(printB);
        toolBar.add(printerField);
        getContentPane().add(toolBar, BorderLayout.NORTH);
        getContentPane().add(panel, BorderLayout.CENTER);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-500)/2, (screenSize.height-500)/2, 500, 500);
    private void printBActionPerformed(ActionEvent evt) {
        PrinterJob pj=PrinterJob.getPrinterJob();
        pj.setPrintable((Printable)panel);
        PrintService[] services = pj.lookupPrintServices();
        boolean ok = false;
        for( int i=0; i < services.length; i++ ){
            System.out.println("Available PrintService: '"+services[i]+"'");
            if(services.toString().equalsIgnoreCase( printerField.getText() ) ){
try{
pj.setPrintService(services[i]);
ok=true;
}catch(PrinterException ex){
System.out.println(ex.getMessage());
if(ok){
try{
pj.print();
}catch (PrinterException ex) {
ex.printStackTrace();
}else{
JOptionPane.showMessageDialog(this,"Printer not available");
public static void main(String args[]) {
new Print_Demo().setVisible(true);
private JButton printB;
private JToolBar toolBar;
private JPanel panel;
private JTextField printerField;
class MyPanel extends JPanel implements Printable{
public void paint(Graphics g) {
g.drawRect(100,100, 100,100);
public int print(Graphics g, PageFormat pageFormat,
int pageIndex) throws PrinterException {
if(pageIndex>0) {
return NO_SUCH_PAGE;
paint(g);
return Printable.PAGE_EXISTS;

Similar Messages

  • There is a problem communicating with the printer.

    I have a Lexmark Interpret S405. I am using a MBP laptop with WiFi, running 10.5.8. I have a cabled (non-wifi) Linsys router. I am using an Airport Express.
    I was finally able to get the WiFi light on the Lexmark to be static green after reinstalling the Lexmark WiFi setup and reconfiguring my Airport settings so that both the computer and printer see each other.
    In fact, I even updated the driver from Lexmark's Web site last night and I watched the WiFi light on the printer blink green indicating that the installation of the driver update was being communicated to the printer.
    However, when I print, it opens the print window and says first "Looking for S300-S400", then it says "Printer is now online". Then after about 10 seconds, I get this error: "There is a problem communicating with the printer. Make sure the printer is powered on and connected to the computer. Delete or hold the job and try again."
    I've exhausted Lexmark's technical databases and couldn't find the answer here.
    I've read that one possible solution was to delete all the printers from the "Print & Fax" system preferences window and re-add. That didn't work.
    Lexmark says for: The printer communicating on a network; however, the printer is not responsive. Possible causes could be:
    1. Your printer is associated with a network, router, or access point, but it is not your network.
    2. A software process is blocked by a system security firewall preventing network communication.
    3. You are logged into Virtual Private Network (VPN).
    4. You are connected to a network but have decided to switch to a USB connection.
    I don't have a VPN and have removed the USB cable, then restarted both printer and computer, and deleted printers in Sys Prefs, restarted, and still no solution.
    I can print directly via USB cable, but want to print wirelessly.
    Lexmark also says to enter my PIN (which I have pulled out from the print menu screen on the printer) in the System. That tells me a lot...
    Network settings on the print window on the printer also tell me Signal strength is 5 (excellent) and that I am on the network my airport is on.
    Message was edited by: Macman17

    I bet this is too late but...
    Are you trying to print through the airport express wirelessly or the built in wireless of the lexmark? If you want to use the airport express, there is no need to mess with the wireless printing on the lexmark at all. The airport express will be easy to set up, all the wireless setups through the printers are a pain.

  • How do I set the print and paper size in iPhoto 5

    Can somebody please help. How do you set up iPhoto 5 so that you define both the the size of the print and the photo paper you use?
    For example, I wish to print a 4.5cm x 3.5 cm photo on 6x4 (or 15cm x 10cm to keep all the units the same) paper.
    I've seen a post saying how to do it in iPhoto 8, but the drop-downs are different.

    I do not remember the locations in iPhoto 5 but there are probably three places to mess with
    1 - set the paper size
    2 - set the print size
    3 - set the paper tray for the printer to use that has the paper size that you set in step 1
    these may be in the print sequence or under the file menu as page set up (or similar). If these are not obvious try the Help menu
    LN

  • How to print the PDF file contains stamps without set the printer options

    I have pdf document, and stamp them with my personal stamp.
    With the printer option under "Comments and Forms", I set to "Document", my stamp DISAPPEARED.
    Unless re-set (use options) to "Document and Markups" or "Document and Stamps" then it will be fined.
    Can I embeding my stamps to my document so that everyone can print without using printer options to contain stamps?
    (regarding to whoever don't know how to set the printer options, and keep asking that I did not stamp on the doc.)
    Please help.
    Thanks in advance.
    th

    Can I embeding my stamps to my document so that everyone can print without using printer options to contain stamps?
    Yes, you can.

  • How do I set the print area in Numbers?

    How do I set the print area in Numbers?

    Hi Macuser4ever,
    Numbers does not have the 'Set Print Area' feature. Numbers is designed around several tables, each with a purpose. For example, Input Table, Big Database, Intermediate Calculations Table (all of which you may not need to print) and a final Summary (Presentation) Table that you may wish to print. The Summary Table can be on its own Sheet. Arrange objects (Summary Table, Charts [graphs] and whatever) on one Sheet and print only that Sheet.
    If you are using Numbers 3.x (Layout View and Print View missing) try this User Tip:
    Print Layout Guide for Mac Numbers 3.2
    Regards,
    Ian.

  • Report 3.0 : How to set the printer margin??

    Hi all,
    In report previewer, I am able to set the printer page margin
    mannally.
    Then, If, I've get some reports by RUN_PRODUCT in batch mode,
    how can I set the page margin??
    Regards,
    Andrew
    null

    Hi amole,
    one more doubt,
    Iam new to use BAPI_ENTRYSHEET_CREATE.
    What are the mandatory fields that should be passed to it to create SES ( Service Entry Sheet ).
    The data given to me is:
      Purchase Ord number,
      Activity Number,
      Rate,
      Quantity,
      External Number.
      Is the above data is enough to create SES.
      please clarify.

  • Problem in setting the smtp in a apple mail account.

    Can anyone help me resolve a problem in setting the mail preferrences? I have multiple email accounts and the smtp address is being deleted to a none smtp in an account then when I fix the problem in one account it deletes an smtp address in another email account. When I fix that account it deletd another smtp address and so on an so forth. Is this a virus or is there a fix for this problem?

    Mail in IOS iPhone or OS X?
    Anyway You select each account and assign or create new smtp.

  • Can you set the print margins in Preview?

    Simple question: Is there a way to set the print margins when printing an image from Preview?
    Thanks,
    -ME

    EagleSongs wrote:
    I can set margins in other programs (like Photoshop, Word, Excel, Firefox, Chrome...), but there does not seem to be a setting for margins when printing from Preview. I don't want to resize the image, just get it to print in a certain position on the paper (template form).
    In the case of Photoshop, you are placing an image on a canvas and can position the image to suit. Word and Excel have a Page Setup menu that lets you set the margin positions - which know since you have got the output you wanted. There is no Page Setup menu for most, if not all, Apple applications like Preview. Instead parts of the Page Setup menu have been added to the print dialog but margins is not one of them.
    EagleSongs wrote:
    However, I was trying to find a way to print from Preview and get it to position the image on the page the way I want.
    Understood. Unfortunately you don't get that option in Preview. The image will be centred - both horizontal and vertical - based on the paper size and the printer you have selected in the print dialog. You could create a custom paper size with the margins you want to position the image and then use that custom paper in Preview. But your workaround of using Word gives you more control over the positioning of the image.

  • Looking to buy an ipad but the only problem is that the printer that i have only prints using a wire. is there a product that i can buy so i can use the same printer??

    looking to buy an ipad but the only problem is that the printer that i have only prints using a wire. is there a product that i can buy so i can use the same printer??

    It might be less hassle to buy a new printer.
    List of supported AirPrinters.
       http://support.apple.com/kb/HT4356
    printing to a non-airprinter from an iPad
    To print from the iPad, your going to have to install some more software:
    -- install a printer app on the ipad. many printer makers have iPad applications for their printers.  Look in the app store
    -- install enabling software on a computer which you have connected the printer
    For a comprehensive list of links, see Texas Mac Man list:
    https://discussions.apple.com/message/21291967#21291967
    There are iPad Print Applications supplied by printer manufactures -- usually free.  Check for your prineter.
    Helper app -- /print n share
    Print directly to the widest range of network or WiFi printers available in any app. Alternatively print via your computer to ALL printers including USB & Bluetooth printers. View read and display large PDF, Office & iWork files. Easily transfer & store files from the Cloud or your computer.
    https://itunes.apple.com/us/app/print-n-share/id301656026?mt=8
    Software for your computer's printer:
    Mac and Windows
      FingerPrint
        http://reviews.cnet.com/8301-19512_7-57368414-233/fingerprint-turns-any-printer- into-an-airprint-printer/
    Makes any printer AirPrint® compatible so you can print from an iPad® or iPhone®.
        Reportedly works for any router.
        http://www.netgear.com/landing/genie/default.aspx

  • There was a problem connecting to the printer. Make sure it's connected and try again

    A test page prints ok. However when I come to print any document I get this message:
    "There was a problem connecting to the printer. Make sure it's connected and try again"
    I have uninstalled the printer and re-installed it and rebooted my computer. Still printing a tet page but won't print anything else.

    Hi @davifels,
    Welcome to the HP Forums!
    I see that you are getting the error message, "there was a problem connecting to the printer. Make sure it's connected and try again." With your HP Envy 4500 printer running on Windows 8.1 (64-bit). I am sorry to hear this, but happy to help!
    For further assistance, I will need the following information:
    If the printer is connected, Wireless, or USB.
    If the printer is able to make copies. Copy Text or Mixed Documents.
    If the power cable is plugged into a surge protector, or directly to the wall outlet. Issues when Connected to an Uninterruptible Power Supply/Power Strip/Surge Protector. This applies to Inkjet printers as well. 
    If the printer can print from NotePad.
    In the meantime, please take a look through this guide, 'Printer is offline' Message Displays on the Computer and the Printer Will Not Print: Windows 8.
    Hope this guide helps, and hope to hear from you soon!
    RnRMusicMan
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to say “Thanks” for helping!

  • Setting The Printer For Reverse Or Mirror Image

    Hello,
    IM trying to create some T-Shirt Transfers, but I Would Like To Know How To Set The Printer For Reverse Or Mirror Image?
    Thanks!

    click print, go to 'preferences', under the 'finishing' tab, orientation section your choices should be [ ]portrait, [ ]landscape, [ ]MIRROR IMAGE.

  • I'm going to set the printer on fire: A short essay

    Thank you HP. Thank you for the usable service life of this C6180 all-in-one rage creation machine. And here I thought I was just buying a printer. Where to start? Maybe with the fact that every time I blink, the printer becomes magically Offline, like Merlin himself was here watching me with a mischievous attitude and a crooked little wand. And to switch the printer from Offline to Online? Impossible. There is no button for that. At least not for my feeble level of intelligence. If it exists, maybe I need a Masters degree in "Navigating Windows 7", because all the normal clicking functions provide absolutely ZERO assistance in making this printer Online again. Hooray for wireless bluetooth connectivity, I feel the wave of the uncomplicated, convenient future washing over me every time I scratch at my eyeballs to alleviate the pain when the C6180 decides to no longer be available for my printing needs. Oh, there's a fix. I can simply remove the device and reinstall it, which used to give me a modicum of satisfaction, like i was exercising the evil nymphs possessing my printer. But the thrill of that has long since faded and now, as I'm in a feverish rush to get somewhere and the only thing holding me back is the network discovering my "new" printer so I can reinstall it and print whatever insignificant drivel I might need for my obviously utterly unimportant and inconsequential endeavors, the effort to get this thing "Online" seems more like the thrill associated with disembowelment or maybe drowning in a shallow, shark infested pool. It's not that I particularly mind wasting 2 minutes at a time here and there to print directions or a rebate form... Oh no wait, that is it. That is what I hate. Being forced into repeating this painfully absurd process at the whim of a PRINTER.
    Further, can someone explain this whole ink thing? Why when I've printed maybe a handful of documents, the illustrious C6180 happily informs me that ALL of my ink cartridges need to be replaced?? They expire? I'm sorry, ink expires? I have a 60 year old Ho-Ho in my kitchen that I could go pound down right now with no ill effect, but the printer ink expires within my lifetime? How am I suddenly responsible, with the purchase of this delightful piece of equipment, for using up all the ink in a prescribed amount of time?? I'm not a print shop. I don't design and sell wedding invitations. I'm just a guy. I print a paper for school here and there, one day I might feel exceptionally adventurous and maybe print a picture. And now, since I have become affiliated with this printer, HP has decided how much ink I should be using and in what time frame?? No, you'll say, HP just supplies the equipment, you use it at your discretion. Fine, fine, maybe that's it. Or maybe I have a HUGE problem with spending $80 on INK that's going to EXPIRE before I can USE IT!!
    Another thing.. Why is it that my printer sounds like 4 Mack trucks and a freight train colliding with a dynamite factory every time it feels like doing some "printer preparation"? I was not aware that so much steel and hydraulics and steam powered anti-aircraft ammunition could be packaged in such a small, unassuming package, and then miraculously used to print something once in a while if the stars align and the printer ink is within it's tse tse fly lifetime and the gods of connectivity have deemed me worthy for the printer to be Online. And good grief, if I try to turn on the printer or wake it up and print something, I might be lucky if the C6180 stops doing it's own thing sometime in the next few hours and returns my phone call. 30 minutes of printer preparation for a 3 page paper? Maybe that's where all that ink is going. 
    And lastly, as my fury and rage begin to dissipate, I have only last question. Why, for the love of Pete, won't this thing print a BLACK AND WHITE page because the MAGENTA INK IS LOW??! Can someone please explain to me how the MAGENTA IN ANY WAY relates to the printing of a BLACK AND WHITE document?! What do I know about color? What do I really know about anything? Apparently the C6180 knows far better than I which inks (out of black and magenta) really go into printing something... black.. Maybe there's something to it, maybe there isn't, all I know is that I went to Staples yesterday and bought a $20 black ink cartridge so I could at least print in black and white, and now the printer sits there grinning at me, with my $20 in its gullet and satisfaction smeared all over its smug face. Look at it. "Cannot print" ever so happily displayed on its little screen. Orange exclamation point flashing away in cheeky mockery of my anguish. Just oozing self-satisfaction knowing that I'm writing all of this to vent, and the only replies I'm likely to see are to the tune of "Hey, welcome to the wonderful world of printers, buddy." Satisfaction that it has usurped another few precious minutes of my life. I could have been at the grocery store, or visiting my mom. Maybe I could have found love in these squandered moments. I could have worked toward becoming a better me, but instead I sat my rear end on this drum stool and hammered out a statement of hate and violent protest against this reprehensible HP creation. Even to get to this point, I had to create an HP something-or-other account to get to some place to type, because this seemed easier than setting myself up with the tech service (or any customer service) department.
    I wash my hands of this. In the coming days I will decide whether to replace the remaining 5 ink cartridges in this machine or just buy a new one, because that might honestly be less expensive. Maybe I'd sell the 6180. Maybe I'd set it on fire. I know for sure I won't shoot it, that's too god for it. I want it to suffer...

    That is priceless!!!  Thanks!  I sure needed a good laugh after spending/wasting hours & days trying to either get my c6280 to give up on its Ink System Failure fixation, or find a decent replacement.  Unfortunately I need the Smart Web Printing feature that I guess only HP has, or I'd try a different brand. And now even HP has very few models with that available.
     My error msg is a little different from those previously stated, but close:  0xc18a0201.  Even tho there were frustrations with my c6280, I did like several of its unique features which are hard to find now under $100.  I hate how HP (& I suppose other brands also) are CONSTANTLY changing models & then of course ink cartridges.
    Oh heavens, I've had the c6280 a whopping 2 1/2 years!   I'm sure they want us poor slobs to have to buy a new one every year & a day!  To say nothing of the exorbitant prices for ink.  And now if this one is really dead in the water, I have SIX unused #02 ink cartridges which I cannot return---I got them in a combo pack, & for some reason have wound up with THREE lite pink & THREE lite blue cartridges, while having to buy extras of the other colors, that ran out before the others!!!   Yeah, & what's with that not being able to print in BLACK if a color runs out????
    Anyway I really loved your essay!   It's a classic!  And says it all!  I hate that we have to be 'slaves' to the electronic 'wonders'!!!

  • #*$!%! Can't figure out how REALLY to set the printing defaults so they STICK for everything

    PLEASE DON'T REPLY HERE.  PLEASE REPLY TO MY IDENTICAL POST AT 
    http://h30434.www3.hp.com/psg/board/message?board.id=Software&thread.id=5348
    On our 6-month old HP OfficeJet Pro 8500 Wireless A909g, we can't seem to figure out how to set the DEFAULT printing parameters so they really apply to all docs (unless we designate otherwise for a particular doc, of course).  When we set them, sometimes they work for the next doc, and sometimes they revert back to an earlier setting.
    There seem to be three ways to set parameters for the printer: Properties, Printing Preferences or Printing Defaults on the Advanced tab.  (We really thought Printing Defaults on the Advanced tab would do it, since it's so hard to find, but ... NOT.)
    My partner thinks it's an HP conspiracy to sell more ink because the reversion is to General with Color (the most ink-intensive, as far as I can figure out).  We are trying to fix the machine to start always with Fast-Economical/Black Ink Only.  Sometimes it's there and sometimes we have to re-jigger first.  We still have to check every time.
    Also, I want to fix every job to "Print Back to Front" because the printer shoots out the pages face up.  Again, sometimes it's there, and sometimes we have to re-set before the job.
    Also, whether we get the default we had set or we re-jigger first, the settings don't stick for every worksheet in an Excel workbook.  Or sometimes not even every page. 
    So, who out there has the 100% foolproof guide to NAILING DOWN THOSE SETTINGS FOR EVERYTHING?
    PLEASE DON'T REPLY HERE.  PLEASE REPLY TO MY IDENTICAL POST AT 
    http://h30434.www3.hp.com/psg/board/message?board.id=Software&thread.id=5348

    Locking this accidental double post and directing people to the linked original thread.
    Clicking the "Kudos star" to the left is a great way to say thanks!
    When your problem has been solved, accept the solution by clicking the "Accept as Solution" button to help other members in the future!
    Rules of Participation

  • How to setting the printing option in javafx 2.1 or later?

    Hi,
    We need to printing pdf document in our project, it's can use the open source to do it now, but it's has some problem when running the program in other pc.
    Step 1, It's setting the program with full screen in our program.
    Step 2, In the button event, we call JDK swing print dialog to setting the page option.
    They will not bring the swing frame to front, and the Javafx program unable to response cause by the swing printdialog.
    If anybody know how to deal with the paper option setting by Javafx, Please help me, thanks a lot.

    Vibhor - You are developing using the Oracle Application Express facility running on Oracle Database 10g Express Edition. You can export applications you develop there for use on Oracle Application Express versions 2.0 and higher which can be used with Oracle Database server versions 9.2.0.3 and higher.
    Electing to install an application as Run Application Only will prevent the editing of the application definition by the end user. This can be useful if you assume that the end user will have access to the Application Builder in his database, which is likely if the end user's database is Oracle Database 10g Express Edition (XE). However, there is no way to prevent an XE user from having complete control over applications installed into those databases. If the end user's database is not XE, then only an Oracle Application Express site administrator will be able to change the application's Run Application Only setting to Run and Build Application but all developers with developer accounts in the Application Builder will be able to view and edit the application definition.
    Further, when you say "he can easily access my code", remember that the application definition is contained completely within the export file that you distribute but you may have in mind your PL/SQL source code as well. PL/SQL can be wrapped using a utility to make it more difficult to see in clear text.
    Scott

  • Why the window setting the printing disappeared when I try to select the page number of pdf file

    When I send the pdf file to the printer and try to select the page number to be printed by entering (e.g., 4-10), the page for setting up printing work suddenly disappeared.   As a result, I could only print pdf files from page 1 to the end, if I want to print any document.   I have no problem with printing word documents.  Thus, it should not be problems related to printer, right ?
    Your help is highly appreciated !

    What is your operating system?  Reader version?
    You mean the Print panel completely disappears when you enter some page numbers?

Maybe you are looking for