String Pixel Length in 1.1

I'm writing an applet the wants to run on IE without plugins. That means that I have to use 1.1. I want to draw a series of strings and need to know where each ends so I can position the next one. None of the methods for this in 1.2 are available to me. FontMetrics seems to be available in 1.1, but it is an abstract class and I can't figure out how to subclass it without using those same 1.2 methods.
I can't seem to find anything about it on this forum.
Anyone got any examples?
Thanks!

int lengthInPixels = yourComponent.getFontMetrics(yourComponent.getFont()).stringWidth(yourString);Hope its enough for you.

Similar Messages

  • Pixel length of text in applet output useing drawString()

    is thier a way to find the pixel length of a string of text when im going to output it useing drawString in a applet
    to say i am going to "draw hello world" in a applet
    i wish to use drawRect around it i know were it starts i want to know the length of the letters in pixel size
    each one seems to differ so each letter has a unknown length i need to know the lenght of the combined letters of the string of text
    or even each individual letter and i can write a algorithim to add um
    this is a problem ive encoutered before never solved and now am encountering again.

    The TextLayout class is also handy in this area.
    /*  <applet code="TextSizeTest" width="400" height="300"></applet>
    *  use: >appletviewer TextSizeTest.java
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class TextSizeTest extends JApplet
        public void init()
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(new TextSizePanel());
        public static void main(String[] args)
            JApplet applet = new TextSizeTest();
            JFrame f = new JFrame(applet.getClass().getName());
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(applet);
            f.setSize(400,300);
            f.setLocation(200,200);
            applet.init();
            applet.start();
            f.setVisible(true);
    class TextSizePanel extends JPanel
        String text;
        Font font;
        public TextSizePanel()
            text = "A test string";
            font = new Font("lucida sans regular", Font.PLAIN, 24);
            setBackground(Color.white);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int w = getWidth();
            int h = getHeight();
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics metrics = font.getLineMetrics(text, frc);
            float width = (float)font.getStringBounds(text, frc).getWidth();
            float ascent = metrics.getAscent();
            float descent = metrics.getDescent();
            float x = (w - width)/2;
            float y = (h + ascent)/2 - descent;
            g2.drawString(text, x, y);
            g2.setPaint(Color.red);
            g2.draw(new Rectangle2D.Double(x, y - ascent, width, ascent + descent));
    }

  • String with length 1 became 4 when nls_lang_semantics=CHAR

    Hi,
    We are using Oracle 9.2.0.1 database with charset = UTF-8, and we have set nls_lang_semantics=CHAR.
    We got a problem in our java program is that for a column with char(1), after I insert a java constant 'Y', the result I get back from select is a string of 'Y ', i.e. the string returned is not a string with length=1, but with length=4!! How can I correct the problem to get a string with length=1?
    Regards,
    Roy

    Hi,
    Thanks for the responses but I don't think you're quite right. Forms 6i should indeed work with Unicode as a database character set as long as it is UTF8 rather than AL32UTF8. This can be seen in various Metalink documents and also in the Release 6i Guidelines for Building Applications here (section 4.1.5):
    http://download-west.oracle.com/otn_hosted_doc/forms/forms/A73073_01.pdf
    The problems started when I changed NLS_LENGTH_SEMANTICS to CHAR. Its understandable if Forms 6i does not recognise this setting as it pre-dates it but I wanted to confirm this.
    We want to migrate our existing application to work with multibyte characters. Unfortunately there are table columns, PL/SQL variables etc. that are too small when defined as a length in bytes.
    I am looking for the least impact method to rectify this. On the server I can use NLS_LENGTH_SEMANTICS but if I can't get Forms to work with it then I may need to rethink.
    I realise that using Forms 9i or 10g would support the parameter but it is not possible to upgrade at the moment.
    Has anyone any other suggestions or methods for migrating an application to using multibyte characters?
    Thanks again,
    Kevin.

  • What does this error means? "Line 20 column 57: character content of element "language" invalid; must be a string with length equal to 3 (actual length was 7) at XPath /package/book/metadata/languages/language" "

    Hi there.
    I am about to publish a book in English and Chinese.
    What does this error means?
    Line 20 column 57: character content of element "language" invalid; must be a string with length equal to 3 (actual length was 7) at XPath /package/book/metadata/languages/language"
    And where is line 20, column 57?
    Thanks folks!

    Go into iTunes Producer and select from the dropdown, don't type.
    cs
    iBooks Author Guide

  • Calculate string CPI (length of string in pixel)

    Word-wrap position is at the moment done in SAP via length of string (count of letters) via function u201CRKD_WORD_WRAPu201D. But this is counting number of char, this give the problem that different font type and size give different word-wrap position ! -> We need to calculate if possible the word-wrap position via the relative length of text u2013 I tried to find some on SDN and Internet, the only thing I can find is some functionality in JAVA u2026
    Can any one help me how to calculate the length of a string using font type and hight of font... as we use truetype font as arial the length of letter "i" is not the same as 'X' ...
    Best regards Jørgen Jensen

    My problem is not to do the wordwrap, my problem is to find the right position as the length of 'i' is not the same length of 'X'
    example:
    iiiiiiiiii (10)
    XXXXXXXXXX(10)
    must be something like this:
    iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii(wordwrap position 35)
    XXXXXXXXXX(Wordwrap position 10)
    I need a way to find the length of a charactor in a given font and size.
    Best regards Jørgen Jensen

  • Pixel Length of a String

    I want to know the width and height, in pixels, of a String when I display it on the Screen using drawString() and a Graphics object. I assume it would be Font-dependent, but I can't find anything about this in the Font class...

    public void paint(Graphics g) {
            Graphics2D g2d = (Graphics2D)g;
            Font font = new Font("Serif", Font.PLAIN, 12);
            FontMetrics fontMetrics = g2d.getFontMetrics();
            int width = fontMetrics.stringWidth("aString");
            int height = fontMetrics.getHeight();
        }

  • String array length

    Can any one tell me how to get the no. of rows and no. of columns in an string array.
    ie if i have array like
    1 2 3 4
    4 5 6 5
    7 8 9 6
    in an a[][]. how to fine values ie row =3 and col = 4

    Assuming that the array is a rectangle (all rows have the same number of columns) and that it's two dimensional, you can do this:
    int row = a.length;
    int col=a[0].length;
    I think that works, try it

  • Field type String (long length more than 1500)

    Hi All,
    we have requirement like one custom table with field string type(1500 length) should update through the report.
    problem is, it is not updating that many characters through the report.
    (till 255 chars only updating in the table)
    i have to update full string in the custom table.
    the code is below, please help me any one come accross the situation.
    thanks in advance.
    data: lv_test type string,
          lv_test1 type string,
          lv_num type i,
          it_test type table of ZFEILD_TEST,
          wa_test type zfeild_test.
    do 10 times.
    lv_test = 'thptjpojtgpeojygpeojhpoewjhpojwhjwpohjopsjhoptrjhopjwhopjwpojhpowjhopwjojwpojhpowjhpowjkahglfdglkaglkahklrhlfhslhkalklklhkalhalkhlahlkajljhlajhlajlajlkajlhjaljlajlhjaljhlajhlahpojwpohjwopjhojhwjhojopjwopjhwojhotjhwojwhojwpojhpwojhpowjophjwpojh'
    lv_test1 = lv_test.
    concatenate lv_test lv_test1 into lv_test1.
    clear: lv_test.
    enddo.
    lv_num = strlen( lv_test1 ).
    wa_test-STRIN = lv_test1.
    wa_test-znumber = '001'.
    append wa_test to it_test.
    loop at it_test into wa_test.
    write: / wa_TEST-strin.
    modify zfeild_test from wa_test.
    endloop.

    Hi,
    I assume you have chunks of the string and you need to concatenate it and put it to the table.
    You can try this.
    data : begin of w_string occurs 0,
             string type string,
             end of w_string.
    data  : w_char1(255) type c value 'BLAUGBUSSUSSF',
              w_char2(255) type c value 'GSIUHFSHF',
    w_string-string+0(255) = w_char1.
    w_string-straing+255(255) = w_char2.
    so on....
    append w_string.
    Regards,
    Pramod

  • String Fields Length

    Hi,
    Length of string fields in my crystal report are locked to 20 by default, but my data source's query's field length is 50.  How can I fix the crystal report to show all 50 characters in the report?
    Thanks and regards,
    Al

    Hi Hitesh and Crystalier,
    Thanks for your replies.
    I check marked "Can Grow" option and it didn't work.
    Database is SQL Server 2005 and my connection is OLE DB (ADO).  The database field is VARCHAR(50).
    I noticed, under the Field Explorer -->  Database Fields, the type of the field is showing as "String [20]".  But the field in the datasource (SQL Server 2005) is Varchar(50).  Also, when I right-clicked Browse Data on the field on Field Explorer, the data that was returned are all trimmed to 20 characters.
    Thanks and regards,
    Al

  • ExternalInterface.call String parameter length limit???

    Is there a String length limit to the amount of chars a
    String can contain when passed as a parameter to
    ExternalInterface.call()?
    Also, are there any chars that ExternalInterface.call()
    cannot serialize in a string?? Like \n, \t ...etc.
    The livedocs don't answer these questions.

    thanks for your reply but i just figured it out.
    ExternalInterface.call("jsFunc", longString);
    There is seems to be no char limit that i came across cause i
    was able to shove 2K in there.
    The problem is the newlines in the string, they must get
    messed up during serialization. Just make sure you clean the string
    of newlines like so:
    longString = longString.split("\r").join("
    ").split("\n").join(" ");
    ExternalInterface.call("jsFunc", longString);
    works fine......

  • Javascript function for validating string for length

    hi all,
    i am having a string whose datatype is CHAR in the database and length is 7 .
    can any one help me with the javascript validation code(function) for this?
    regards and thanks in advance

    sigh Another user to the ignore list. :)You should see this thread
    http://forum.java.sun.com/thread.jspa?threadID=632908&tstart=0ram.

  • Parse string by length

    I have a incoming data string that is Hex, which is comprised of messages that have a string length of 98 characters (no delimiters).  How do I got about parsign this these strings?  I've tried to use something like a match regular expression, or a scan from string, inside a while loop.  Offsetting the incoming string by 98 characters, trying to read a formatted string (%98s), then building an array of the found messages, until I have reached the end of the string.  But I am unable to get this approach to work properly.

    How about a loop that spits the string at the 98th character.  This attached picture shows a loop that will create an array of strings with each element (except possibly the last one) is 98 elements in size.
    Message Edited by paulmw on 10-20-2006 12:51 PM
    Attachments:
    stringArray.JPG ‏10 KB

  • Sort string by length

    Hi Everyone
    I have a set of data
    qqq
    adadada as
    aas a
    asada
    adasdas adada
    now I need a formula which can sort these strings according to the length. So the longest string will come at the top. I would really appreciate if anyone could help me with it.
    Thanks

    If you need to code this yourself then simply implement a sorting algorithm, get the two lengths and swap the Strings if necessary.
    If you can utilise the sort method written in Collections class, then you will need to write your own Comparator.
    Read about these classes and try it yourself. If you are still having trouble come back and ask a specific question.

  • Sorting by pixel length/width in Aperture 2.0

    I have a smart album for images to be submitted to a stock agency. This agency requires that the long edge of an image be a minimum of a certain number of pixels. How can I sort out the images that meet those requirements from those that need to be enlarged to meet the requirement? I tried sorting using pixel size, but I'm not sure what "pixel size" means to Aperture exactly, as some images that have clearly larger pixel dimensions get listed in the middle of ones that have smaller dimensions.
    Any ideas?

    Edward Tobin wrote:
    ...Once I return home I upload my photographs into a new project in Aperture for editing. When I am happy with the editing I assign metadata to them to describe the location and keywords.
    IMO no, the first step us to assign metadata that applies to all images in the batch during the import to the entire batch of images. Of course individual images can later get image-specific metadata.
    ...So it looks like projects are not for long term organization.
    IMO projects are very much for long term organization in that each project can fully stand alone. However also IMO good keywording far transcends project organization. E.g. "Tibet 2008" is a project that stands alone, but the keyword "flowers" crosses all projects to present all flowers ever keyworded.
    -Allen Wicks

  • String maximum length

    Hi all,
    I'm facing a simple problem: when building a string using CONCATENATE INTO the result gets truncated to 128 characters although the strings I need to concatenate are longer. The variable type is STRING.
    Any idea?
    Thanks for your help.

    Hi Tomas,
    Are you sure about it?
    Probably the list output widht is not sufficient?
    This worked for me:
    data: v_str type string.
    data: v_str1 type string value
    'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
    data: v_str2 type string value
    'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeex'
    concatenate
    v_str1
    v_str2
    into v_str.
    write: v_str.
    Regards,
    Ravi

Maybe you are looking for

  • Opening a text edit document in Firefox

    Hello, I am a beginning student in web design. I am trying to open a simple document in text edit with Firefox. When I open the file in a new tab, nothing appears. How can I fix this? Thank you

  • HELP...Finding Installed Ringtone Files

    Does anyone know how you find the factory installed ringtones files on a Nokia N95 and N97? I tried using explore your device on Ovi Suite, even with showing hidden files I can not find them. Any help would be greatly appreciated. Thanks in advance.

  • Oracle Text Query of abbreviated word / name

    I'm new to Oracle Text so please excuse the (probably) simple question. I want to be able to create a search that excludes (includes?) special characters and/or spaces between an abbreviated name. I'm not sure if it's possible but I would like to be

  • Photoshop CS6 install

    Can anyone please help me. My old computer does not work anymore. How do I do to install cs6 in to my new computer. I have cs4 and cs6 is an upgrade.

  • XL Reporter Excel security

    SAP B1 8.8  SQL Server 2008 Excel 2007 Hi all, When I try to run XL Reporter, I get a message that says 'Security settings in Microsoft Excel prohibit XL Reporter from running'. I've had a look through all the settings and I can't work out what this