Please Help!! How to get the width of the String for print out?

Hi there,
I need to do some printing in my application. I just want to know how can I get the width of the string when it is printed on the paper.
I have tried to use the following code to get the width
Rectangle2D rec = font.getStringBounds(str, new FontRenderContext(null, true, true));
double width = rec.getWidth();
however, the width I got from that function is not correct (the returned width is longer than the printed one)
Does anyone know how to solve this problem?
Thank you and Happy New Year !

hi,
The getFontMetrics(Font) is also defined in the Component class and therefore you can retrieve it even if you dont override the paint method.
try the following (provided ur code extends some class that extends Component indirectly)
FontMetrics f = this.getFontMetrics(this.getFont());
int width = f.stringWidth(str); //str is the String for which u need to check the width.
hope this was useful
happy holidayz

Similar Messages

  • My ipad2 is asking old id password, when i go to forget password link for that id then I am not getting any mail to reset the same. Please help how can i remove or change the old id.

    my ipad2 is asking old id password, when i go to forget password link for that id then I am not getting any mail to reset the same. Please help how can i remove or change the old id.

    You cannot remove or change the old ID. This is Find My iPhone Activation Lock. You need to recover the credentials for the Apple ID originally used to activate the iPad.
    Check your spam and junk folders.

  • Hi, please help me , i get notification about a new update for my iPad when I do the instal for the new version it is asking me for a passcode but which passcode may I have to enter? Because when I enter my gmail passcode it is call me that my pass fail

    Hi, please help me , i get notification about a new update for my iPad when I do the instal for the new version it is asking me for a passcode but which passcode may I have to enter? Because when I enter my gmail passcode it is call me that my passcode is failed

    The passcode you need to enter is the passcode you set on your device. It is the passcode that you enter when you turn on your iPad or awaken it from sleep after and Auto lock.
    If you do not know or remember your password and did not store it somewhere then you will have to restore your device.
    http://support.apple.com/kb/HT1212

  • Please help-how can I find accents on the keyboard when typing in French?

    Please help.How can I find accents on the keyboard when typing in french?Thanks

    You can also open the Keyboard Viewer & hold Option key & Shift+Option to see...
    Option key...
    Shift+Option or alt key...

  • I keep getting asked to agreed to the new terms and conditions and can not accept them please help, how to get rid of it?

    I need help please I have my i phone, im setting the icloud and it keeps telling me to accept the new terms and conditions but the page wont populate for me to accept it, im getting annoying with it the pop up us making me crazy plase help.

    Try these...
    1)  Press the Accept Button Twice...
    2)  Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
    Wait for the Apple logo to Appear...
    Usually takes about 15 - 20 Seconds... ( But can take Longer...)
    Release the Buttons...

  • Please Help(How to get RadioButtons in tree View)

    Hi.
    Sub/Requirement: How to implement RadioButtons in tree view with/without using xml file.
    I have a requirement like this i want to display RadioButton in tree view.
    I implemented tree same as which is given in sampleApplications.
    In this sampleApplications they implemted tree by using xml file.
    I also implemented tree by Generating xml file. In this xml file i get the values from the database. I am using <netui:tree > tag.
    Is it possible to implement tree without using xml file. I need to generate tree Dynamically.
    Please any one help me to come out with this solution.

    The issue here is while you are retrieving all the details, you are consistently overwriting them in the request.setAttribute() call before you get to the JSP to display them.
    Do you actually have a class/object called Student?
    That object should have attributes for classes, subjects, teachers (all of which are lists apparently)
    public class Student{
      String name;
      List classes;
      List subjects;
      List teachers;
      // appropriate getter/setter methods
    }Then you load each student, and populate its individual lists.
    That lets you pass the list of students, each student having its own lists for display.
    Hope this helps,
    evnafets

  • [PLEASE HELP] How to get Microsoft Outlook Rules to work on my Z10

    Hi, 
    My organization recently started deploying Z10 for work. We use Mircosoft Outlook 2010 and I receive many e-mails throughout the day that I filter by setting up rules. 
    These Outlook rules do not seem to transferr over to my Z10 e-mail account as I am being constantly flooded with these "junk" e-mails. 
    I've tried to change the folder sync settings, but that doesn't seemt to rectify the problem. 
    I have Software Release 10.2.0.429 and OS Version 10.2.0.1803
    Does anyone in this community know about this problem and if there's a solution? 
    Thanks so much. 
    - Kyle 

    DoubleK wrote:
    Hi, 
    My organization recently started deploying Z10 for work. We use Mircosoft Outlook 2010 and I receive many e-mails throughout the day that I filter by setting up rules. 
    These Outlook rules do not seem to transferr over to my Z10 e-mail account as I am being constantly flooded with these "junk" e-mails. 
    I've tried to change the folder sync settings, but that doesn't seemt to rectify the problem. 
    I have Software Release 10.2.0.429 and OS Version 10.2.0.1803
    Does anyone in this community know about this problem and if there's a solution? 
    Thanks so much. 
    - Kyle 
    Unfortunately Outllok rules only work within Outlook itself.
    One way that I have found to partially work is to use the IMAP server (if available in your organisation) from both the computer and the device(s), and to keep Outlook running while you are gone, and then the rules works for most of them
    Using the Playbook and the Z10 and the Z30 and loving them
    Martin

  • Please help trying to get "Remote" app to prompt me for passcode

    I am pretty good at these things and for some reason after installing the app on my iPhone 3G I am unable to use the passcode thats given because I get no prompt on the sidebar to enter it in.
    I see a lot of complaints in the app store about this not working well. Sharing in iTunes is turned on Firewall I have allowing incoming connections. Maybe I'll wait for a update.
    Thanks in advance.

    First of all, are you using Windows or MAC? Second if using Windows XP, try turning off the Firewall Completely:
    1-Right click on My Network Places and click properties
    2-Right click on either Local Area Connection or Wireless Network Connection and click properties
    3-Click on the Advanced Tab, click on Windows Firewall Settings,
    4-Click on the Off balloon and click Ok.
    If you want to check the exception list to make sure iTunes can pass through the firewall click on the Exceptions Tab and make sure that iTunes is checked and click Ok.
    If you are using a Mac I can't really help, and if you are using Windows Vista I can post some options to try as well. Hope this helps!

  • Please help how to get return array from rpg program on java code?

    Hi
    I have created a rpg program that returns 2 parameter 1 is the id and another one is list of array, when I called this program I passed two programparameter from my java code (see the code below) but when i checked what value would be return it is returned only first value of array. how will i get all array values ?
    please suggest me regarding this issues I amn't so much aware on java & AS400.
    try
    ProgramParameter[] parmList = new ProgramParameter[2];
    AS400Text p1 = new AS400Text(10);
    AS400Text p2 = new AS400Text(30);
    try
    parmList[0] = new ProgramParameter(10);
    parmList[1] = new ProgramParameter(30);
    parmList[0].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[1].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[0].setInputData(p1.toBytes("Pune"));
    parmList[1].setInputData(p2.toBytes(" "));
    catch(Exception ex)
    ProgramCall pgm = new ProgramCall(o);
    pgm.setProgram("/QSYS.LIB/XXX/XXX.PGM",parmList);
    if (pgm.run())
    byte s[] = parmList[1].getOutputData(); // HERE I got only first value of returning array.
    parmList[1].getOutputDataLength();
    //String sts = ((String) (new AS400Text(10,o).toBytes(s[0])));
    else
    AS400Message[] messageList = pgm.getMessageList();
    for (int msg = 0; msg < messageList.length; msg++) {
    catch(Exception ex)
    AS400Message[] messageList = null;
    finally
    o.disconnectAllServices();
    Reply With Quote

    Try this :
    try
    ProgramParameter[] parmList = new ProgramParameter[2];
    AS400Text p1 = new AS400Text(10);
    AS400Text p2 = new AS400Text(30);
    AS400Array arrP2 = new AS400Array(p2, 4);
    try
    parmList[0] = new ProgramParameter(10);
    parmList[1] = new ProgramParameter(30);
    parmList[0].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[1].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[0].setInputData(p1.toBytes("Pune"));
    parmList[1].setInputData(arrP2.toBytes({"","","",""}));
    catch(Exception ex)
    ProgramCall pgm = new ProgramCall(o);
    pgm.setProgram("/QSYS.LIB/XXX/XXX.PGM",parmList);
    if (pgm.run())
         Object[] objArr =  (Object [])arrP2.toObject( parmList[1].getOutputData() );
         for(int i =0; i<objArr.length;i++){
                System.out.println( " SKU " + i +" : " + objArr.toString());
    else
    AS400Message[] messageList = pgm.getMessageList();
    for (int msg = 0; msg < messageList.length; msg++) {
    catch(Exception ex)
    AS400Message[] messageList = null;
    finally
    o.disconnectAllServices();

  • Please Help: How to get Image under JDK 1.1

    Hi all out there!
    The following is my problem:
    I need to get an image under JDK1.1.
    What I want to do is get a graphics-object from
    it and draw some stuff onto it. Afterwards I want
    to save it to some file (gif, png). The latter part is
    no problem. But I couldn't find a concrete subclass
    under JDK1.1. I know of BufferedImage in JDK1.2
    but that doesn't help too much since I'm restricted
    to JDK1.1.
    Anyone who can help me with this?
    Greetinx
    Valentin

    hi,
    what about Toolkit.getDefaultToolkit().getImage(String)regards

  • Please guide how to get Webcam operated & resolve the color therein

    My webcam,I am not able to go to it's settings to adjust the photos & color therein.

    Sagarika,
    Please go thru the dev guide which explains the train flow in the multistep update exercise. Compare the steps with ur implementation.
    - Senthil

  • I have iOS 6 on my iPhone. i have linked my contacts with facebook and yahoo, which has doubled or triplicated some of the contacts. how can i integrate them into one? please help. it is getting on my nerves. thanks :)

    I have iOS 6 on my iPhone. i have linked my contacts with facebook and yahoo, which has doubled or triplicated some of the contacts. how can i integrate them into one? please help. it is getting on my nerves. thanks

    click on the contact which you want to integrate, click the edit button scroll down u will find a option called link contacts use it to link it to the duplicate contact

  • Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?

    Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?
    I'm developing an application where a file is need to be saved as pdf. But, if there is already a pdf file with same name in the specified directory, I wish to overwrite it. And in the overwrite case, read-only files should not be overwritten. If the duplicate(old) file is opened in windows (Win7) explorer preview, it is write protected. So, it should not be overwritten. I tried to get the '
    FILE_ATTRIBUTE_READONLY' using MS API 'GetFileAttributes', but it didn't succeed. How Adobe marks the file as read-only for preview? Do I need to check some other attribute of the file?
    Thanks!

    Divya - I have done it in the past following these documents. Please read it and try it it will work.
    Please read it in the following order since both are a continuation documents for the same purpose (it also contains how to change colors of row dynamically but I didnt do that part I just did the read_only part as your requirement) 
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0625002-596c-2b10-46af-91cb31b71393
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0155eb5-b6ce-2b10-3195-d9704982d69b?quicklink=index&overridelayout=true
    thanks!
    Jason PV

  • Please Help,how do i get my iphone 4 to play all my songs from icloud, it is currently only playing just a smal number of songs from my library which is stored in icloud.

    Please Help,how do i get my iphone 4 to play all my songs from icloud, it is currently only playing just a smal number of songs from my library which is stored in icloud.

    There are a number of OS X apps, many free, that will save your messages, allowing to view and print them. 
    http://www.softwarebbs.com/wiki/How_to_transfer_SMS_from_iPhone_to_Mac,_backup_i Phone_SMS_message_on_Mac
    Google, for other options
    Your "other" of 6 GB may include corrupted data or file sytem errors. If after removing the messages there is still >2GB, you will need to restore the phone in iTunes, first using a backup (made after deleting the messages) and if needed as a new iPhone.
    iTunes: Restoring iOS software

  • For updation of IOS 7.1.1 passcode required,I forget my passcode please help how can I get my passcode

    Hello,
    I forget my passcode please help how can I get my it

    You will need to try to restore your iPad from the same computer that you most recently synced to.
    Read this: http://support.apple.com/kb/ht1212
    If you can't do the restore then you will need to try Recovery Mode.
    Read this: http://support.apple.com/kb/ht1808
    Follow the instructions very carefully.

Maybe you are looking for