Not able to change font

Hi ,
We need to print some text data in printer. As we print a report, with numbers, and columns, we need font widht to be constant for all the charecters for producing properly aligned reports. [ like in courier or monospace fonts]. In the code below, I am not able to set the font for my printer. In the print() method, I tried to set font as monospace for the graphics object, but it did not have any effect. It looks like it always print with Ariel font. For displaying in layouts, it works find. But not with printer. Please help.
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.text.*;
* The PrintText application expands on the
* PrintExample application in that it images
* text on to the single page printed.
public class PrintText implements Printable {
* The text to be printed.
private static final String mText = "this is the string to be printed";
* Our text in a form for which we can obtain a
* AttributedCharacterIterator.
private static final AttributedString mStyledText = new AttributedString(mText);
* Print a single page containing some sample text.
static public void doPrint() {
/* Get the representation of the current printer and
* the current print job.
PrinterJob printerJob = PrinterJob.getPrinterJob();
/* Build a book containing pairs of page painters (Printables)
* and PageFormats. This example has a single page containing
* text.
Book book = new Book();
book.append(new PrintText(), new PageFormat());
/* Set the object to be printed (the Book) into the PrinterJob.
* Doing this before bringing up the print dialog allows the
* print dialog to correctly display the page range to be printed
* and to dissallow any print settings not appropriate for the
* pages to be printed.
printerJob.setPageable(book);
/* Show the print dialog to the user. This is an optional step
* and need not be done if the application wants to perform
* 'quiet' printing. If the user cancels the print dialog then false
* is returned. If true is returned we go ahead and print.
boolean doPrint = printerJob.printDialog();
if (doPrint) {
try {
printerJob.print();
System.out.println("successfully Printed");
} catch (PrinterException exception) {
System.err.println("Printing error: " + exception);
* Print a page of text.
public int print(Graphics g, PageFormat format, int pageIndex) {
/* We'll assume that Jav2D is available.
Graphics2D g2d = (Graphics2D) g;
/* Move the origin from the corner of the Paper to the corner
* of the imageable area.
g2d.translate(format.getImageableX(), format.getImageableY());
/* Set the text color.
g2d.setPaint(Color.black);
/* Use a LineBreakMeasurer instance to break our text into
* lines that fit the imageable area of the page.
Point2D.Float pen = new Point2D.Float();
AttributedCharacterIterator charIterator = mStyledText.getIterator();
int tabCount=100;
int[] tabLocations = new int[tabCount+1];
int i = 0;
for (char c = charIterator.first(); c != charIterator.DONE; c = charIterator.next()) {
if (c == '\n') {
tabLocations[i] = charIterator.getIndex();
System.out.println("found newline at tabLocations[" + i + "] = "+ tabLocations[i] );
i++;
tabCount=i;
tabLocations[tabCount] = charIterator.getEndIndex() - 1 ;
int currentTab = 0;
float verticalPos = 20;
charIterator = mStyledText.getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, g2d.getFontRenderContext());
TextLayout layout;
float wrappingWidth = (float) format.getImageableWidth();
while (measurer.getPosition() < charIterator.getEndIndex()) {
if (currentTab < tabCount )
layout = measurer.nextLayout(wrappingWidth,tabLocations[currentTab]+1,true);
if (measurer.getPosition() == tabLocations[currentTab]+1) {
currentTab++;
else
layout = measurer.nextLayout(wrappingWidth);
pen.y += layout.getAscent();
float dx = layout.isLeftToRight()? 0 : (wrappingWidth - layout.getAdvance());
layout.draw(g2d, pen.x + dx, pen.y);
pen.y += layout.getDescent() + layout.getLeading();
System.out.println("Print result : "+ Printable.PAGE_EXISTS);
return Printable.PAGE_EXISTS;
}

I don't see how it would have worked on the screen. Is that what you meant by "For displaying in layouts, it works find."? You never called setFont(...) on the Graphics or Graphics2D object in your paint method. Use g2d.setFont(new Font("Monospaced", Font.PLAIN, size)) and you should be fine.
Jeff

Similar Messages

  • Email will not let me change fonts all of a sudden.

    Email will not let me change fonts all of a sudden.  It says I don't have the neccesay permissions in ~/library/preferences.  this has just happened recently.

    Who is your email provider?
    You can try resetting your iPad by simultaneously pressing and holding the Home and Sleep/Wake buttons until you see the Apple Logo. This can take up to 15 seconds so be patient and don't release the buttons until the logo appears. Try again to see if the problem persists.
    If yes, try deleting the mail account and adding it again.

  • HT4847 I have a new iphone and cannot delete the backup from icloud.  It says that it is in use.  I have read some of the other threads and it only seems to be haphazard solutions. Is there a definite way to fix this? I am not able to change icloud accoun

    I have a new iphone and cannot delete the backup from icloud.  It says that it is in use.  I have read some of the other threads and it only seems to be haphazard solutions. Is there a definite way to fix this? I am not able to change icloud accounts.

    Follow the steps in wjosten's post here: https://discussions.apple.com/message/13356770#13356770 (for Windows, substitute Outlook in step 2).

  • Not able to change sales stage from requirtement to reqmt analysis

    in opportunity Not able to change sales stage from requirtement to reqmt analysis
    Error Message:SBL-DAT-00284
    Details error msg is:
    Unable to evaluate workflow rule for foll reason
    Update probability between 0 & 100%(SBL-ODS-00500)
    Edited by: user1074008 on Sep 22, 2010 10:17 PM
    Edited by: user1074008 on Sep 22, 2010 10:18 PM

    Looks like a bug...
    Previos Post Activity Status = Submitted - Access Denied

  • Not able to change exportfolders value in MBeans for FRConfig.cmd for Hyperion Financial reporting 11.1.2 version.

    I am not able to change exportfolders value in MBeans for FRConfig.cmd for Hyperion 11.1.2 Financial reporting .
    When I enter the value , it just vanishes. Am I missing something here.?
    I need to set export path for PDF generation in Hyperion financial report for batches.

    Edit FRConfig.cmd and update
    set EPM_ORACLE_INSTANCE=%MIDDLEWARE_HOME%\user_projects\epmsystem1
    update epmsystem1 to the correct epm instance name
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • How do I change the country for my iTunes account? I had purchased some itunes gift cards and i have about .75USD left in it. I am not able to change the country because i have to clear the account balance. there is any way I could spend that money???

    I would like to change my country from US to Thailand in the iTunes Account. I purchased some iTunes gift card to purchase some apps and since ever i was not able to change my account balance to 0.00USD which is needed in case I want to change my account country. I appreciate if some body can help with this

    1) Buy something 75c or greater and charge the balance to a credit card.
    or
    2) Contact Apple and ask them to keep the 75c
    iTunes Customer Service Contact - http://www.apple.com/support/itunes/contact.html > Get iTunes support via Express Lane > iTunes > iTunes Store

  • User not able to Change Password in Webaccess

    We are running GroupWise 7.0.3 HP3. We have one user who is not able to change her password in Webaccess. Whenever she tries, she get the following error message in Webaccess
    Ldap Password Change Failed. Contact your system administrator.
    When I look at the POA screen on the server, I see the following error message.
    LDAP Error: 53.
    Her account is not disabled, expired or locked. I get the same error message when the account has an unlimited number of network aconnections.
    If I change the password in ConsoleOne and log into the account, I get prompted change my password because it has expired.
    Thanks

    n,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Visit http://support.novell.com and search the knowledgebase and/or check all
    the other self support options and support programs available.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://forums.novell.com)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://forums.novell.com/faq.php
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://support.novell.com/forums/

  • My iCloud is defaulting to an old Hotmail address that I no longer use, my apple ID is currently functioning fine with a gmail account.  I'm not able to change my iCloud email on my phone or on desktop... Any advice?

    My iCloud is defaulting to an old Hotmail address that I no longer use, my apple ID is currently functioning fine with a gmail account.  I'm not able to change my iCloud email on my phone or on desktop... Any advice?

    You would have to change your Apple ID back to your old hotmail address (https://appleid.apple.com ) in order to turn off "Find My iPhone" and change the iCloud ID. After you changed it back and verified your old hotmail address you should be able turn off "Find My iPhone" and to temporarily delete your iCloud account from your devices. After that you can change your Apple ID back to your gmail address again. After it is verfied, you could add back your iCloud account by using your gmail address.

  • My past billing adress of my apple ID is the states, presently i'm in montreal Canada and im not able to change the billing address because my balance is $ 0.68, any idea how can i change it?

    my past billing adress of my apple ID is the states, presently i'm in montreal Canada and im not able to change the billing address because my balance is $ 0.68, any idea how can i change it?

    You can contact iTunes support and request that they remove the $0.68 from your account here:
    http://www.apple.com/support/itunes/contact/
    They should respond within 24 hours.

  • Not able to change the the Contract Line Item Payer

    Hi there,
    I am not able to change the Contract Line item Payer and giving an error message '' Credit limit customer differs from credit limit customer in header''.
    I checked the credit management assignment and the Business partner is assigned with the required Payer.
    Request your help.
    Thanks,
    Renjith

    Hi Renjith
    So first of all  check with which customer you have created Contract. So go to CMR data and check wheather you have maintained multiple Payers or not. If not maintained maintain multiple payers.
    As you are getting error  '' Credit limit customer differs from credit limit customer in header'' , so check the payer at header level and item level also. the payer at header level and item level should be different.
    Regards
    Srinath

  • Not able to change vendor name while creating a DC under a track in NWDS

    Hi all,
    I am trying to create a new DC under a track in NWDS.I am not able to change the vendor name .It is showing sap.com and the field  is greyed out.Did anybody faced this issue earlier?
    Need your inputs.
    Thanks and regards,
    Rajesh

    Hi Rajesh
    Please check this thread.
    cannot create a new DC
    You can create new SC with your name reservation and add to your track.
    Hope this will help you.
    Thanks
    Arun

  • Not able to change Company Code in f-58

    I have done a payment with T-code f-58 in Co. Code XXXX.
    Now I want to do a payment in Co. Code YYYY with f-58 but I am not able to change Co. Code.
    Co Code field is in display mode.
    I have searched on SCN but did not get any correct solution.
    Plz suggest

    Dear nisit shah,   Press F3 - then the company code will be in the edit mode and you can change the company code.    n.selvakumar.

  • Not able to change UOM in material master for a material

    Hi all ,
    I have a issue with changing of the UOM in the material master , IN MMO2  after changing the UOM , in Display error , its showing the error as : The base unit of
                                         The reasons for
                                         Manual  reservation
                                         Reserv.No   , Item - No data
                                         Purchase order  - 30017056  , Item 1 - 1
    There is no stock in the previous as well as current period , and deleted the PR , still i am not able to change
    Please help urgently
    Thanks in Advance
    Neha

    Hi Satyajit,
    Please look at OSS  Note 1069560 - Data inconsistencies: Activating integration. models in parallel, if this helps you.
    Since  Gross data of material is in the basic view, it is common across plants , whereas, IMs are normally designed to have material masters at plant level.
    We may have same material in different IMs with different  plants. Therefore changes of the basic view fields are then contained in multiple IMs.  SAP advises to have a larger IM or sequential activation of IMs.
    I hope this will  help you .
    Regards
    Datta

  • SRM 7.0 Buyer not able to change SC in Sourcing cokcpit.

    HI Everyone,
      I remember, in SRm 5.0, buyer can change shopping cart whole sourcing from sourcing cokpit. Has this been changed in SRM 7.0? We are nota able to change the SC in Sourcing cockpit.
    Thanks,
    SG

    SAP rules says that
    You cannot change a shopping cart directly from the sourcing application.
    http://help.sap.com/saphelp_srm70/helpdata/en/d8/33ec56f17f4404806072749f7e764f/frameset.htm
    Since  REQUESTER department requested only BUYER department has to source.
    BUYER can identify the vendor and add / price only in the cockpit.
    Since conflict between REQUESTER and  BUYER  department.
    BUYER duty is whatever REQUEST department has requested needs to be sourced.
    Note 1435354 - Sourcing Cockpit:Product Category field editable in SC
    Add a shopping cart to the Purchaser's Workarea in the Sourcing Cockpit and click at the link of the Shopping Cart item the Shopping Cart item will be opened in change mode and the Product Category field is shown as editable. As per standard design of Sourcing Cockpit, the product category of the item should not be editable in the Sourcing Cockpit.This note corrects the error and displays the Product Category field of the Shopping Cart as read only.
    Muthu

  • Buyer not able to change fields of SC in sourcing cockpit in SRM 7.0

    Hi
    We are on SRM 7.0 , SP 07 . We are in classic mode.
    Buyer is not able to change fields of shopping cart in sourcing cockpit like delivery date and quantity . He is able to add supplier and create PO . Even when he creates draft PO , he is not able to edit the fields of shopping cart like delivery date and quantity. Is it a standard Bug , is their any OSS SAP Note for this
    Regards
    Ashish

    As per SAP Standard BUYER can only vendor and Enter price and create  a follow on document.
    Buyer does not have a control to edit other data.
    Buyer wants to they can do it in ME21N ..PO
    not in the shopping cart

Maybe you are looking for

  • Connecting 6 displays to 1 computer

    Im thinking to buy 3 Msi NX7600 (pci-express) display adapters and connect them into Msi K9N Ultra-2f motherboard. Motherboard seems to have 3 pci-express 1x slots, is it even possible to connect display adapter to this slot? I need to show high defi

  • Select (variable) into:parameter from xyz , dynamic sql

    hello everyone I have a table with the columns KZ01*01*, KZ01*02*, KZ01*03*..... I want to select the value from one column depending of a variable z.b. varable=3 I want the value select KZ01*03* I wrote the trigger post_querry: declare      v_kfz st

  • Print the attachements added in the adobe form

    Hi, I added the attachments in the adobe form.But when ever i print this adobe form , i want to make sure that the attachments are also printed in addition to the original adobe form. Is there any automatic way of doign it or any alternatives to avoi

  • Post Moved No-phoneline-after-switching-from-Sky...

    Moved http://community.bt.com/t5/Phones/No-phoneline-aft​er-switching-from-Sky-to-BT/td-p/782646 If you want to say thanks for a helpful answer,please click on the Ratings star on the left-hand side If the reply answers your question then please mark

  • GridBagLayout on top of other layout manager

    Hi, I am trying to put a GridBagLayout within a GridLayout and it is not showing up. What's wrong? Thanks, Steve import java.awt.*; import java.awt.event.*; import javax.swing.*; class TestButton {     public static void main(String[] arguments) {