Results 1 to 6 of 6

Thread: An urgent doubt

  1. #1
    priyaa is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default An urgent doubt

    Hi all, i have a issue with java 6. after displaying printdialog and clicking 'ok' or cancel, doesnt return focus to the application. the application focus is lost. how to solve this issue?

    The part of the code i am attaching here

    public void printDrLicBondCardRtnEnvelopes()
    {
    new Thread()
    {
    public void run()
    {
    printEnvelopes();
    }
    }.start();
    }

    public void printEnvelopes()
    {
    int[] selectedRows = frame.table.getSelectedRows();
    if(selectedRows.length == 0)
    {
    JOptionPane.showMessageDialog(null, "Select rows for printing labels.",
    "Print Labels", JOptionPane.INFORMATION_MESSAGE);
    return;
    }

    //NMM(07/21/2008)
    if(isSelectedEnvelopesPrinted())
    {
    String allOrSome = allSelectedEnvelopesPrinted() ? "all" : "some";
    int status = JOptionPane.showConfirmDialog(null,
    "Envelope(s) printed on " + allOrSome + " selected row(s)" +
    "\n Print envelope(s) again?",
    "Envelope Print status", JOptionPane.YES_NO_OPTION);
    if(status == JOptionPane.NO_OPTION)
    return;
    }
    //NMM END
    addCasesToLabels();
    if(addressMap.size() == 0)
    {
    frame.addMessage("No records available for printing labels");
    return;
    }

    if(addressMap.size() > 0)
    {
    int noOfPages = addressMap.size();
    printer = (profile.isSuperUser() || profile.hasToken(PRINTER_NAME_TOKEN)) ?
    promptPrinters(noOfPages) : null;
    if(requestCancelled)
    {
    frame.addMessage("Printing cancelled...");
    return;
    }

    formatEnvelopes("MAILPAY ADDRESS ENVELOP", addressMap, printer);
    //updatePrintedLabelsStatus();



    frame.toFront();
    updatePrintedEnvelopeStatus();
    refresh();
    }
    }

    public void formatEnvelopes(String reportName, TreeMap data, String printer)
    {
    int pageNo = 0;
    ReportRequest request = createReportRequest(reportName, printer);

    ReportFreeFlowBuilder builder = loadFreeFlowReportBuilder(request,
    pageNo + 1);

    builder.initFirstPage();

    PrinterJob job = PrinterJob.getPrinterJob();
    ProgressDialog dialog = getProgressDialog("Printing DrLic/BondCard Return Envelops");
    dialog.setVisible(true);
    String id1;
    Vector v1;
    Font font = new Font("Monospaced", Font.PLAIN, 10);
    Font font8 = new Font("Monospaced", Font.PLAIN, 8);

    Address addr1 = null;
    String name1 = null;
    int rowsProcessed = 0;
    int totalRows = data.size();
    Book book = new Book();
    for (Iterator i = data.entrySet().iterator(); i.hasNext();)
    {
    id1 = (String) ((Map.Entry) i.next()).getKey();
    v1 = (Vector) data.get(id1);
    dialog.getProgressBar()
    .setValue(
    dialog.getProgressBar().getValue()
    + (++rowsProcessed
    * dialog.getProgressBar()
    .getMaximum() / totalRows));

    name1 = (String) v1.firstElement();
    addr1 = (Address) v1.lastElement();
    String line1 = getFillString(2) + id1;
    String line2 = getFillString(X_ENV) + formatName(name1);
    String line3 = getFillString(X_ENV) + formatAddrLine1(addr1);
    String line4 = getFillString(X_ENV) + formatAddrLine2(addr1);
    String line5 = getFillString(X_ENV) + formatCityStateZip(addr1);
    builder.startNewPage();
    builder.addData(new PageElement(DATA, "\n\n", LEFT, font8));
    builder.addData(new PageElement(DATA, line1, LEFT, font));
    for (int j = 0; j < 7; j++)
    {
    builder.addData(new PageElement(DATA, "\n", LEFT, font));
    }
    builder.addData(new PageElement(DATA, line2, LEFT, font));
    builder.addData(new PageElement(DATA, line3, LEFT, font));
    builder.addData(new PageElement(DATA, line4, LEFT, font));
    builder.addData(new PageElement(DATA, line5, LEFT, font));
    builder.getCurrentPage().setNoOfPagesToPrintPerJob (totalRows);
    book.append(builder.getCurrentPage(), job.defaultPage());

    }
    job.setPageable(book);


    try
    {
    if (job.printDialog())
    job.print();

    }
    catch (Exception ex)
    {
    JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error Printing Envelopes", JOptionPane.ERROR_MESSAGE);
    ex.printStackTrace();
    }

    dialog.getProgressBar().setValue(dialog.getProgres sBar().getMaximum());
    dialog.closeWindow();
    frame.toFront();
    frame.addMessage("Label Printing completed...");
    }
    Last edited by priyaa; 08-17-2010 at 02:36 PM. Reason: code also attached

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Welcome to forum. :)

    Please choose the correct sub-forum when you are posting again.

    Your questions, did you set the component owner in dialog?

  3. #3
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    I'm not sure but something like this do :
    Java Code:
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.showDialog(parentFrame, "Save");
    -regards

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Multiposted all over these forums.

    db

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. [URGENT]SHA Encryption System...need urgent helps
    By java_idiot in forum New To Java
    Replies: 6
    Last Post: 05-02-2010, 10:04 AM
  2. have doubt
    By ras_pari in forum Advanced Java
    Replies: 3
    Last Post: 10-01-2009, 09:51 AM
  3. doubt
    By Chris555 in forum Networking
    Replies: 0
    Last Post: 08-05-2009, 02:58 PM
  4. doubt
    By shaju_inspira in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 01-18-2008, 08:38 AM
  5. doubt in jms
    By veena in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 01-05-2008, 01:42 PM

Posting Permissions

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