How many pixels does a string occupy??

I'm making a credit script and have a little problem with centering the
strings. If one string is eg. 12 characters long how many pixels will it occupy on screen? This depends on which letters the string contains. So the question is, HOW can i calculate the space (in pixels) needed to print any given string. (The size of the letters is constant!)
Is it any other way to center a string on screen? I have a tendency to think a little complicated.. :)
Any help is welcome. Code or just ideas is great!

Hi
There's a Graphics method very interesting:
g.getFontMetrics()
it recover the width of an String...Code of sample: (Sorry, but I'm from Spain and my code too):
public void paint(Graphics g)
g.setColor(cLinea);
g.draw3DRect(5,5,iAncho-10,iAlto-10,true);
g.draw3DRect(6,6,iAncho-12,iAlto-12,true);
Color c=this.getBackground();
if(!bAgra)
{ g.setColor(Color.orange); }
else
{ g.setColor(cObligatorio); }
g.fill3DRect(7,7,iAncho-13,iAlto-13,true);
g.setColor(cLetra);
g.setFont(new Font("Dialog",Font.BOLD,iSize));
//Next line recover the X position referenced by the canvas width/2 and the text width/2...result:CENTERED
int posX=(iAncho/2)-(g.getFontMetrics().stringWidth(sTitulo)/2);
//Oopss. I've tried to do a vertical align to center, but it doesn't work properly...
int posY=(iAlto/2);
g.drawString(sTitulo,posX,posY+5);
If you need more help about this code, don't worry to ask me again
Greetings

Similar Messages

  • How many pixels to use for scanning newspaper article with photos

    I recently purchased an EPSON Perfection V600 Photo scanner to make CDs of family stories, newspaper articles, pictures, film, and slides.  It comes with Adobe Photoshop Elements 9.  I was hoping to restore old photos.  I have several old newspaper articles that were written by an aunt who was a freelance writer for various publications.  The articles also had photos. They have aged and have a yellow tint.
    I have tried to scan them, but the photos look grainy and the background is still yellow.  My Brother printer does better than this.  I am trying to put together a booklet with the history of our family so future generations will be able to read and see their heritage.  This is a very important project to me, but I think I am not capable of doing this. 
    My question today is how many pixels and dpi do I select?  Or is that what is causing the distortion?  It looks kind of like the glass windows in your car look like with polarized glasses.
    Thank you for your help

    I don't think the issue is so much pixel size and dpi, but more the scanner settings. I downloaded the user manual for your scanner. There is a Descreen setting which most scanner have. The manual says about Descreen: "Removes the rippled pattern that can appear in subtly-shaded image areas, such as in skin tones. Also improves results when scanning magazine or newspaper images which include screening in their original print processes. This setting is available only when the Image Type is set to Color or Grayscale. The results of descreening do not appear in the preview, only in your scanned image."
    The manual also mentions a Newspaper setting: "when you select Newspaper as the Document Type setting, the Image Type is set to Black&White". However, if the yellow is converted to gray there are ways in PSE to remove the gray. Even if you scan the newspaper in color, there are ways in PSE to remove the yellow.
    If you try the above and are not happy with the results, you might post an example of the scanned picture and reader of the forum can offer suggestions to improve it.

  • How many users does HFM support?

    Hi,
    how many users does HFM support(Maximum)? and why we are choose HFM compare to Hyperion enterprise?
    thanks
    Edited by: user10919054 on May 18, 2009 3:07 AM

    There is no limit, as long as you pay for the licenses and make sure you have a robust system to support user connectivity and demand.
    Hyperion Enterprise is the previous Consolidation tool most commonly used by many companies. Think of HFM as the "New Generation"....

  • How many hours does a brand new battery last after fully charged. I have a late 2008 Macbook Pro.

    How many hours does a brand new battery last after fully charged. I have a late 2008 Macbook Pro.

    clintonfrombirmingham is right, there is no way to exactly tell. But from personal experience, a new battery on a 2008 will last for about 2 1/2 hours with a higher screen brightness and doing something taxing to the battery (like gaming or running lots of 3D programs). But if you're just listening to music with the brightness all the way down, and no programs running, you could get up to 12 hours. So for average use, it should last you a whole business day (assuming you don't use it more than 30% 0f the time). Hope this kind of gives you more of an idea of what to expect:)

  • How many pictures does a 30 GB ipod video hold?

    how many pictures does a 30 GB ipod video hold? and i know it is probably somewhere on the website but i couldnt find it. could someone please answer me soon, thank you.

    A 30GB iPod will hold as many photos as will fit in 27.75GB of space. If some of the iPod's capacity is used for music or other purposes, fewer photos will fit on the iPod. Apple's site specifies 25000 photos.
    (13341)

  • How many times does the JDBC sender adapter retry ?

    Hi All,
    How many times does the JDBC sender adapter retry in the  ' Retry Interval' specified .
    I know that it retries after the time specified in the ' retry interval' , but if it again fails after the first retry will it retry again and again .And while doing it will it block the next Select query which should get executed.
    Thanks & Regards,
    Rahul

    Hi,
    The no of times to be retired on failure of message is default 3 times.
    You can set this in Visual Administrator->Server->Services----> SAP XI Adapter
    Thanks
    Swarup
    Edited by: Swarup Sawant on May 30, 2008 7:19 PM

  • How many records does SAP object BAPIE1VARKEY contain

    Hi Folks,
    I have just started learning ABAP.
    And i have following queries in mind.
    how many records does SAP object BAPIE1VARKEY contain?
    regards,
    Nithin

    Going on an interview? Going to try to fool a savvy tech manager?  I hope not...  How about you tell me why the answer is not two?

  • How many records does JDBC adapter can obtain in one polling?

    Hello everybody,
    I need to do an interface between legacy system and SAP ECC, the legacy systems have a DB so i use the jdbc adapter (sender) and receive the information to SAP ECC with proxy, so i need to activate the polling option from my jdbc adapter working as a sender, i read a table with lot of records, and i need to know how many records does jdbc adapter support when the polling is executed, because is necessary read all records from the table and change the status of the processed field.
    Is possible to get all the records from that table in one polling interval (50,000 records aprox)?, or i need to do the polling by blocks of records until finish all records from the table?, the second option, i dont have idea how can i do it.
    Regards,
    Vicman

    Hi again!,
    i still working on that, but i have a question, is possible to handle Store Procedure in jdbc adapter?? is supported?, like PL SQL, because i was working in the next query but i don't know if it works and where do i need to locate the query in the Query SQL Statement or in Update SQL Statement field or both? but how?.
    DECLARE c_cursor CURSOR FOR
    SELECT * FROM tablename
    WHERE processed=0
    OPEN c_cursor
       FETCH NEXT FROM c_cursor
    WHILE @@FETCH_STATUS = 0
    BEGIN
       update tablename set processed=1
       FETCH NEXT FROM c_cursor
    END
    CLOSE c_cursor
    DEALLOCATE c_cursor
    Regards,

  • How many sessions does SAP allow you to have ??

    Dear Memebers,
    How many sessions does SAP allow you to have ??
    a) 3
    b) 6
    c) 9
    d) 12.
    I guess the right answer is B and C but in choices I have to select only 1, which answer will you pick and Why ??
    Thank You.
    Madhu.

    > I wanted to know for sure what is the answer.
    Hi Madhu,
    If you are going to ask questions such as these, then please indicate that you have searched and what you do already know and where & why you have a doubt somewhere which is worth discussing in the forum or sharing opinions or experiences on.
    Just asking for the answer only so that you don't feel too alone when answering 6 in the interview is of little value.
    Normally such "answer a, b, c, or d only or be quiet"-type-threads (like certification tests are) are deleted. That is the rules, and we have them for a reason.
    Anyway, you guys seem to have sorted this out amongst yourselves so there is no reason to interfere here IMO. Thanks for that.
    Cheers,
    Julius

  • How many minutes does the iPad 2 record in the video mode of the camera?

    How many minutes does the video mode on camera (ipad2) record?

    It should only restart once, see this article:
    iTunes: Restoring iOS software

  • How do I find out how many pixels an image is in iPhoto?

    I need to send a picture for uploading on a staff site, they need a picture of 360 pixels, how do I find out how many pixels an image is in my iphoto library and how do I change the number of pixels if it is too small?

    alt + cmd + i

  • How many sites does the 35.99 get you

    Hello with business catalyst how many websites does the 35.99 get a client? I am a new partner and want to be sure I am giving correct information. Am i reading this right that it gives you 5 sites?

    Hi there,
    If you are a creative cloud account holder and paying the monthly for that you get 5 very basic versions of BC.
    For that price you mention:
    http://www.businesscatalyst.com/pricing/yearly
    You get one webcommerce package (1 site)

  • How many Hz does my ipod touch 4g's screen have?

    HEllo
    i was wondering how many Hz does my ipod touch 4g's screen even have i searches around on google and didnt really find much . And also what resolution and ppi's does it have
    thanks

    Lcd screens do not have refresh rate.
    The 4G uses
    PowerVR SGX535 GPU[45]
    GPU. You can go here to gend some details on the GPU.
    http://en.wikipedia.org/wiki/PowerVR#Series_5_.28SGX.29

  • HOW MANY SONGS DOES A 30 GB REALLY STORE

    Hi-how many songs does a 30 GB really store--currently on approx. 1140 and I'm near half way full--I am concerned I think perhaps I should have gotten the 80GB

    "Also is there a way to buy songs from the iTunes Store in apple lossless?"
    Unfortunately no. That is one of the, several, complaints about the iTMS. First you have "protected" files that are not convertible to other formats (not directly anyway; you can burn to Audio CD then reimport), are not portable to other music players (again, not directly, work arounds exist), and to top it all off, they are advertised as "CD quality" but really you are buying a rather low bit rate for about the same as if you just went out and bought the physical CD instead. Of course, with CDs you can not buy just the tracks you want.
    Hey maybe that is what Apple should do. Sell individual songs at 128kbps/MP4 but if you buy the full album you instead get 192+kbps/MP4s. Then you encourage the real audiophiles to buy albums, not singles. And artists can not complain that the iTMS method only sells their main hits and allowing users to not discover the other songs on their albums.
    Patrick

  • How many bytes does a DATE use?

    Having trouble finding this in the 10g documentation. How many bytes does a date data type use?
    thanks.

    Take a look to the online documentation linked below :
    Oracle® Database SQL Reference
    10g Release 2 (10.2)
    Part Number B14200-02
    Oracle Built-in Datatypes
    expecially code datatype 12.
    Valid date range from January 1, 4712 BC to December 31, 9999 AD. The default format is determined explicitly by the NLS_DATE_FORMAT parameter or implicitly by the NLS_TERRITORY parameter. The size is fixed at 7 bytes. This datatype contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It does not have fractional seconds or a time zone.
    Nicolas.

Maybe you are looking for