Getiing length of String in pixels.

I need to set up legth of combobox depending on length of strings in it. Can I get length of String in pixels?

You should use the getFontMetrics() method of the Graphics object used by the painting methods of the combo.
Then the stringWidth(String) method of the given font metrics should give you the needed width.
Just take care of the fact that the combo must be realized (set visible or packed) for this to work.

Similar Messages

  • 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

  • Find the length of a string in pixels

    Hello all,
    Wondering if there's a way in PowerShell to find the length of a given string in pixels?

    That would depend on the font used to draw it, including size, bold / italic, etc.  Assuming you know those things, there's a TextRenderer.MeasureText method in the Windows Forms library:
    $string = 'This is my string. There are many like it, but this one is mine.'
    $font = New-Object System.Drawing.Font('Arial', 12, [System.Drawing.FontStyle]'Bold, Italic')
    $size = [System.Windows.Forms.TextRenderer]::MeasureText($string, $font)
    $size.Width

  • Length of text in pixels?

    hi, is there any function that gives you the length of a string in pixels? For example, an "i" is a lot smaller than a "m". I currently have a statement like this...
    g.drawString(stringVariable,50-(stringVariable.length()*3),50)
    that gives aproximately centered text... But if I were to type 10 "i"s then it would be way off to the left of 50,50 and if I typed 10 "m"s it would be way off to the right of 50,50, somebody please help on this.

    Hm, I did a little looking up about fontMetrics, and I found my answer, thanks.

  • Determine length of string without function module

    hai experts,
    i need to know how to determine length of string without function module strlen'
    regards,
    karthik

    Please SEARCH in SCN before posting.

  • Width of a string in pixels

    is it possible to get the width of a given string in pixels, if so how to do it ??

    Yes, and you can get the FontMetrics from java.awt.Component (i.e. from all the awt and swing components) with getFontMetrics()

  • Length of a string in pixel

    Hello,
    I am programming a servlet which produces html pages. The page contains a table with more than one column. The columns have a static width of 200 pixel. Now, I want to put some strings into the cells of the table. Depending on the width in pixel, there shall be one ore more cells in a row reserved for one string. How do I know the width of a string in the browser in pixel?
    My idea was, to create a Label within the java-servlet with the right font and fontsize. Then I can get the length in pixel:
    pixellength = testLabel.getFontMetrics(theFont).stringWidth("string to measure");
    That works very well, if the Server has a GUI. If not, the following exception occurs:
    java.lang.NoClassDefFoundError at
    java.lang.Class.forName0(Native Method) at
    java.lang.Class.forName(Class.java:130) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62) at
    java.awt.Font.initializeFont(Font.java:310) at
    java.awt.Font.(Font.java:346) at
    The servlet should work on non-GUI servers as well! What can I do now? Any ideas?

    Hi!
    I don't really know if I'm right on this, but:
    If U use nonproportional fonts (like courier) can't U calculate it by multipling the fontsize (which is in pixels) by the stringsize (number of characters)? i.e.: "Teststring" in fontsize 15 would be 150 pixels wide?
    Thomas.

  • How to find length of string after encryption using DBMS_CRYPTO package

    Hi,
    I am planning do data encryption using DBMS_CRYPTO package. I want to find how much will be string length after encryption.
    e.g When I try to encrypt string of length between 1-15 characters it gives me encrypted string of 32 characters. When I try with 16 charcters encrypted string is of 64 characters.
    Is ther any formula to calculate length of encrypted string?
    Thanks
    Pravin

    The length change is dependent upon the algorithm you are using which can be a combination of cipher block, padding, and chaining.
    The best solution is determine the method you are going to use and apply it to the l ongest possible strings you are going to proces, then add some safety margin. There iis no penalty for defining your column as VARCHAR2(4000).

  • How to find Length of String

    Hi
    how to find length of a string.. i have a requirement that user cannot add more than 9 digits in a string.. i am new to WD Abap..
    Regards,
    Puneet

    Hi,
    You can use STRLEN command for your requirement.
    First read your input field using code wizard.
    Then using STRLEN command you can find the length of the Input field.
    For Example :
    Here input is your input field.
    data :    length type i.
    length = strlen(input).
    If length < 9.
    raise error msg.
    endif.
    Edited by: Viji on Mar 26, 2008 11:30 AM

  • Restricting the length of strings...

    I'm wondering if it is possible to restrict the length of a string produced by the String.valueOf(double) method. Here is an example:
    public class DoubleTest
         public static void main(String[] args)
              double d = 20.0;
              double d2 = 2.4;
              double value = (d/d2);
              String doubleString = String.valueOf(value);
              System.out.println(value);
    }This code will output "8.333333333333334" when run. Is there a way to restrict it to fewer decimal places, for example: "8.34"?
    Thanks a lot,
    Eric

    If you use DecimalFormat, you can specify the number of digits after the decimal point by using a 'pattern' in the constructor to DecimalFormat.
    Use '#' in the pattern for digits which will not show any leading zeros.
    Use '0' in the pattern for digits which will show zeros - this is the one to use after the decimal point to show how many decimal places you want showing.
    This format will round the numbers either up or down depending on which is nearer.
    See example below for usage :
    import java.text.*;
    public class DoubleTest{
         public static void main(String[] args)     {
              double d = 400000.0;
              double d2 = 2.4;
              double value = (d/d2);
              DecimalFormat df1 = new DecimalFormat("#.000");
            System.out.println(df1.format(value));
    }This returns 166666.667 (i.e. 3 places after the decimal, rounded up).
    Regards,
    Fintan

  • Limiting length of Strings....

    Hello,
    I'm just starting to learn Java, and I'm trying to set up a 30 character limit on a String input from the user. I'm using TextIO for the input.
    Can anyone help me out with this?

    You can't (in a cross-platform way) prevent them entering more than your limit, you can however, check, after they've entered their string, that strings length.
    I hope this helps
    Talden

  • GrabFrame() to return a string of pixel information?

    Hi everyone,
    Basically what im looking for is creating a 2d array of values(but id be happy with a string) corrosponding to each of the 320*240 pixels of my camera. At the moment i can get back an awt image using:
    Buffer buf = frameGrabber.grabFrame();
    Image img = (new BufferToImage((VideoFormat) buf.getFormat()).createImage(buf));
    I would of thought that i should meerly use the toString() method. But if i toString() buf i get:
    javax.media.Buffer@22c95b
    and if i toString() img i get:
    BufferedImage@22c95b: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 320 height = 240 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0
    If anyone could help, and point me in the direction of the right method to use, i would be greatly appreciative.
    Thanks.

    You will need integer values from an image to do anything meaningful with the data. Something like this -
    int redValues = new int[imageWidth * imageHeight];
    int greenValues  = new int[imageWidth * imageHeight];
    int blueValues  = new int[imageWidth * imageHeight];
    int alphaValues  = new int[imageWidth * imageHeight];
    int counter = 0;
    public void grabEveryPixelInThe Image(Image img, int x, int y, int w, int h) {
            int[] pixels = new int[w * h];
            PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
            try {
                pg.grabPixels();
            } catch (InterruptedException e) {
                System.err.println("interrupted waiting for pixels!");
                return;
            if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                System.err.println("image fetch aborted or errored");
                return;
            for (int j = 0; j < h; j++) {
                for (int i = 0; i < w; i++) {
                    doOnePixel(pixels[j * w + i]);
    public void doOnePixel( int pixel) {
            int alpha = (pixel >> 24) & 0xff;
            int red   = (pixel >> 16) & 0xff;
            int green = (pixel >>  8) & 0xff;
            int blue  = (pixel      ) & 0xff;
           redValues[ counter] = red ;
           greenValues [ counter] = green ;
           blueValues  [ counter] = blue ;
           AlphaValues [ counter ] = alpha ;
           counter++;
    }regards

  • Maximum length of String

    Hi All,
    Do you know if there is a limit to the size of the string that can be submitted to Oracle database using OraOleDb?
    I wish to run SQL statements that can be very long and I get an error when I submit these statements. I have tried using versions 10.1 of OraOleDb also. Is there a setting in the Connection or query submission that would allow users to submit long strings to Oracle?
    Thanks

    OK, someone's bound to have a rant at IBM or WebSphere here, but a quick knock-up class in WSAD:
    public class StringTest {
         public static void main(String[] args) {
              System.out.println(">> StringTest >>");
              StringBuffer sb = new StringBuffer();
              for (int i=0; i<80000; i++) {
                   sb.append("-");
              String s = sb.toString();
              System.out.println("My String is " + s.length() + " bytes long.");
              System.out.println(">> StringTest []");
    }Gives me:
    StringTest >>My String is 80000 bytes long.
    StringTest []2 to the 16 is 65536, so that's certainly not the upper-limit for a String length in this case.
    And anyway, 2^16 is 18 in Java.

  • Possibility to define length of String fields for POJO Reporting

    <p>It would be a nice feature if you could set the length of a String field in POJO Reporting.</p><p>Right now the max length is set to 127 characters and that is not sufficient for our needs.</p><p>/Thanks</p><p>Mattias Melin</p><p>IST International</p><p>Sweden </p>

    Bascotie wrote:
    To make sure it was not blank I had been using
         if (aCust.state.equalsIgnoreCase("") || aCust.state.length() != 2){
    The first condition is redundant and pointless here, since, if it's true, the second one will always be true.

  • Determine length of string

    In a print statement ie System.out.print(String), how can you ensure that the string will take up a specific number of spaces, for tabulation purposes.

        public final static String padRight(String theString, char thePadChar,
                             int len) {
         if(theString.length() >= len)
             return(theString);
         else
             return(theString +
                 replicate(thePadChar, len - theString.length()));
        public final static String replicate(char c, int count) {
         StringBuffer sb = new StringBuffer();
         for(int i = 0; i < count; i++)
             sb.append(c);
         return(sb.toString());

Maybe you are looking for

  • DVD-R recording/burning problem on Satellite P20

    I have a Satellite P20 notebook with a Multi Dvd-RAM drive (which should support both DVD-RAM, DVD-R and DVD/RW discs for recording). I'm experiencing some difficulties recording data to DVD-R discs - basically when I insert a blank DVD-R the D drive

  • Identify document elements, mark as XML?

    Hi all, Currently working on a Web-to-print project using InDesign Server CS5 and JavaScript. What I'd like to do is enable the following to happen: A user uploads an .indd document (OK with this!). A JS script loops through the document and identifi

  • Upgrading my Broadband package

    Hello, My Broadband service was recently switched over from talktalk to BT. I am currently looking into upgrading from the current package that is being received at my residence. The current package in my house at the moment is BT total broadband opt

  • An error [1130203] occured in Spreadsheet Extractor

    Hello everyone. We have a BSO empty, shell db that is used for reporting. It has multiple partitions to two other ASO db's. A fairly simple Excel Add-in retrieve with ~116 rows and ~186 columns has begun giving users this error (same retrieve used fo

  • Wish to scan doc on 3520 into non-PDF file

    I wish to scan documents that I design into computer from HP 3520 as .RTF, .DOC, .DOCX - anything other than PDF as per previous versons of HP such as Deskjet. Possible rather than paying for conversion costs?