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.

Similar Messages

  • Why does the text look pixelated

    I am using Helvetica Neue and when I publish the site the text looks pixelated.

    Best practice is to use a Web Font, if possible. If not, use a Web Safe Font and only as a last resort use a System Font (since it will be converted to an image). An image is slower to load in your browser, prevents site viewers from copy/pasting your text content, prevents using the browser's Find feature within the page, and prevents you from being able to apply hyperlinks on ranges of text. Muse does automatically generate "alt tags" for the image, so search engines will still be aware of the original text content.
    If a System Font is used, it will only render well if the background of the text frame is 100% opaque. (It has a solid fill color. An 100% opaque gradients. Or it has a 100% opaque fill image.) This is due to the fact smoothing the edges of the type on an LCD display requires knowing the color of the pixels behind the text. If the text frame is transparent then the smoothing will be performed using an inferior approach that is color agnostic to avoid creating color artifacts on the edges of the type. (Note that bringing in a transparent image containing the type from some other source will have the same problem.)

  • 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

  • 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.

  • Max Character Length for Text Variables

    Hi folks,
    Quick question:
    Does OPA have a max character length for text variables?
    -Isamu

    Obviously common sense prevails here. The system is unlikely to perform very well if you start passing around MBs of data in text variables!

  • 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));
    }

  • Length of a string (text) in pixels.

    I'm trying to locate a String's center on an exact position, drawing it to a JPanel. But since i don't know the exact length of the string, it's not that easy. Can anybody help me out there?

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class CenteringStrings
        public static void main(String[] args)
            StringDemoPanel demo = new StringDemoPanel();
            DemoActionPanel action = new DemoActionPanel(demo);
            JFrame f = new JFrame("Centering Strings");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(action, "East");
            f.getContentPane().add(demo);
            f.setSize(500,300);
            f.setLocation(200,200);
            f.setVisible(true);
    class StringDemoPanel extends JPanel
        String text;
        Font font;
        final int
            ASCENT   = 0,
            DESCENT  = 1,
            LEADING  = 2,
            BASELINE = 3;
        int index = -1;
        boolean sizeFlag, boundsFlag;
        public StringDemoPanel()
            text = "Centered text";
            font = new Font("lucida sans oblique", Font.PLAIN, 36);
            sizeFlag = false;
            boundsFlag = false;
            setBackground(Color.white);
        public void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics(text, frc);
            TextLayout tl = new TextLayout(text, font, frc);
            int w = getWidth();
            int h = getHeight();
            float textWidth = (float)font.getStringBounds(text, frc).getWidth();
            float ascent  = lm.getAscent();
            float descent = lm.getDescent();
            float leading = lm.getLeading();
            float height  = lm.getHeight();
            float x = (w - textWidth)/2;
            float y = (h + height)/2 - descent;
            g2.drawString(text, x, y);
            // marker for string origin (x,y) on baseline
            //g2.setPaint(Color.blue);
            //g2.fill(new Ellipse2D.Double(x - 1, y - 1, 2, 2));
            // physical space of text
            Rectangle2D textSize = tl.getBounds();
            textSize.setFrame(x, y - textSize.getHeight(),
                              textSize.getWidth(), textSize.getHeight());
            // string bounds
            Rectangle2D bounds = font.getStringBounds(text, frc);
            bounds.setFrame(x, y - ascent - leading, bounds.getWidth(), bounds.getHeight());
            switch(index)
                case ASCENT:
                    Rectangle2D r1 = new Rectangle2D.Double(x, y - ascent, textWidth, ascent);
                    g2.setPaint(Color.magenta);
                    g2.draw(r1);
                    break;
                case DESCENT:
                    Rectangle2D r2 = new Rectangle2D.Double(x , y, textWidth, descent);
                    g2.setPaint(Color.orange);
                    g2.draw(r2);
                    break;
                case LEADING:
                    Rectangle2D r3 = new Rectangle2D.Double(x, y - ascent - leading,
                                                            textWidth, leading);
                    g2.setPaint(Color.yellow);
                    g2.draw(r3);
                    break;
                case BASELINE:
                    Line2D line = new Line2D.Double(x, y, x + textWidth, y);
                    g2.setPaint(Color.blue);
                    g2.draw(line);
            if(sizeFlag)
                g2.setPaint(Color.green);
                g2.draw(textSize);
                System.out.println("above size = " + (int)textSize.getY() + "\n" +
                                   "below size = " +
                                   (int)(h - (textSize.getY() + textSize.getHeight())));
            if(boundsFlag)
                g2.setPaint(Color.red);
                g2.draw(bounds);
                System.out.println("above bounds = " + (int)bounds.getY() + "\n" +
                                   "below bounds = " +
                                   (int)(h - (bounds.getY() + bounds.getHeight())));
        public void setIndex(int i)
            index = i;
            repaint();
        public void setSizeFlag(boolean flag)
            sizeFlag = flag;
            repaint();
        public void setBoundsFlag(boolean flag)
            boundsFlag = flag;
            repaint();
    class DemoActionPanel extends JPanel
        StringDemoPanel sdp;
        JRadioButton
            ascentButton, descentButton, leadingButton, baselineButton, clearButton;
        JRadioButton[] buttons;
        JCheckBox
            sizeCheck, boundsCheck;
        JCheckBox[] checks;
        public DemoActionPanel(StringDemoPanel p)
            sdp = p;
            createComponents();
        private void createComponents()
            ascentButton   = new JRadioButton("ascent");
            descentButton  = new JRadioButton("descent");
            leadingButton  = new JRadioButton("leading");
            baselineButton = new JRadioButton("baseline");
            clearButton    = new JRadioButton("clear");
            buttons = new JRadioButton[] {
                ascentButton, descentButton, leadingButton, baselineButton, clearButton
            ButtonGroup group = new ButtonGroup();
            RadioButtonListener buttonListener = new RadioButtonListener();
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weighty = 1.0;
            gbc.insets = new Insets(2,2,2,2);
            gbc.gridwidth = gbc.REMAINDER;
            gbc.anchor = gbc.WEST;
            for(int i = 0; i < buttons.length; i++)
                add(buttons, gbc);
    group.add(buttons[i]);
    buttons[i].addActionListener(buttonListener);
    sizeCheck = new JCheckBox("text size");
    boundsCheck = new JCheckBox("bounds");
    checks = new JCheckBox[] { sizeCheck, boundsCheck };
    CheckBoxListener checkBoxListener = new CheckBoxListener();
    for(int i = 0; i < checks.length; i++)
    add(checks[i], gbc);
    checks[i].addActionListener(checkBoxListener);
    private class RadioButtonListener implements ActionListener
    public void actionPerformed(ActionEvent e)
    JRadioButton button = (JRadioButton)e.getSource();
    if(button == clearButton)
    sdp.setIndex(-1);
    return;
    for(int i = 0; i < buttons.length; i++)
    if(button == buttons[i])
    sdp.setIndex(i);
    break;
    private class CheckBoxListener implements ActionListener
    public void actionPerformed(ActionEvent e)
    JCheckBox checkBox = (JCheckBox)e.getSource();
    if(checkBox == sizeCheck)
    sdp.setSizeFlag(sizeCheck.isSelected());
    if(checkBox == boundsCheck)
    sdp.setBoundsFlag(boundsCheck.isSelected());

  • Changing a variables length for text input in Captivate 6

    I am using eLearning CS6 (non-subscription I believe, but no one at my office can confirm) and use a machine where all software is deployed via push from IT. The ability to check for updates has been removed from me.
    I need to be able to have users enter data into the course and have it both be forwarded on to our database AND appear in later segments of the course.
    I recall being able to update the TEB variable length in previous versions but can not find the option anywhere in CS6. or perhaps I'm imaging it.
    I am running version 6.0.1.240 and there is no Format option in my TEB properties. I do not see alignment options, and instead see Characters as a menu above the Shadow & Reflection option.
    I do know where to set the value in a text caption box. However, I seem to be limited to entering a single variable in the caption field in order for this to be option. However, there are times where we'd rather have multiple variables strung together on a single line, or a word or two of static text appearing before or after the variable.
    If I want to string the user entered data from multiple variables into a single caption box there appears to be no way to change the variable's character length from 15 to a higher value.
    Does anyone know of another way to work around this other than through the use of multiple caption boxes?
    I've been driving myself a bit batty trying to think of a way around the 1 caption 1 variable limit...
    Thanks.
    Note: Please don't advise me to upgrade. I've already been told the office will not pay for an update to the software so quickly on the heels of our upgrade from CS 5.5 to CS6 (happened within a 6 month span).

    15 characters is the default when you insert the variable into a text caption.  But you can set this to anything from 1 to about 250...as long as you use the Insert Variable icon in the Properties tab > Format accordion to insert the variable.  Look for the field in the dialog that allows you to specify the variable's display length.

  • How to limit the length of text in a column

    Hello All,
    I have a report built from direct database request.
    I have a comments column , for some of ID's the comment lines are more than 10. For soem rows it is 1 line and for some rows it is having 10 lines.
    Even though in properties if i select wrap text not helping me.
    I want it to show a single line and remaining 9 lines like a link if user wants to see detailed comment he can click on it.
    Can anyone please help me how to achieve this.
    Thansk in advance.
    SR

    Hi SR,
    Which OBIEE version are you using?
    In obiee 11.1.1.7 the column will be extended up to the length of the data(horizontally and vertically)
    Thanks,
    Pavani

  • Text is pixelated in Adobe Viewer when creating an app in indesign

    I am trying to create an app in indesign, I put the docuement in the folio builder, and then view it on my iphone through Adobe Viewer.  The text that I've typed in directly in indesign appears pixelated, along with any thing I placed from photoshop.  In Indesign I've made the object High Quality Display, took out all layers except the text layer, even saved the photoshop text image as a pdf and placed it in indesign, still pixelated.
    Help please.

    Thanks Neil, I did all 3 as per your suggestion: version 25, PDF, and 960*640, and it worked.  But b/c of the PDF option, I believe that was the reason why each page opened up from blurry to clear, which is actually a cool looking effect, however, on some legnthy text frames, the blur took a bit too long to clear.
    So I created another folio, version 25, 960*640 and this time kept it Automatic, and it's just as clear as the PDF folio, but there's no initial blur.

  • How to make the length of Message Dialog follows the length of text

    Hi all.
    I am making a Message Dialog From JOptionPane because i do not want to use some static methods of JOptionPane (JOptionPane.Show ...)
    My source codes following :
    public static void showMessageDialog(String message) {
              JOptionPane optionPane = new JOptionPane();
              JDialog dialog = optionPane.createDialog(null, "Message");
              optionPane.setMessage(message);
              optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
              JButton btnOk = new JButton("OK");
              optionPane.setOptions(new Object[] { btnOk });
              dialog.setVisible(true);
    }It runs well but having a problem. When message is a long text --> JDialog can not show all text, dialog's length does not resize automatically following message's length.
    Have a the way to make it ? How to solve ?
    Thanks in advance !
    Diego
    Edited by: ThuCT on Feb 1, 2010 3:28 AM

    Add a dialog.pack() call. See SSCCE below.
    i do not want to use some static methods of JOptionPane (JOptionPane.Show ...)Why? In this case the built-in static method handles the size as expected.
    public class TestJOptionPaneSizeAdaptsToMessageLength {
       public static void main(String... args) {
           String message = "This is a very long message, I say long but really it is a very very long one, and when I say long I do mean it!!! ";
           message += message;
           message += message;
           message += message;
           showMessageDialog(message);
    //       showMessageDialogUsingStaticJOptionPaneMethod(message);
       public static void showMessageDialog(String message) {
            JOptionPane optionPane = new JOptionPane();
            JDialog dialog = optionPane.createDialog(null, "Message");
            optionPane.setMessage(message);
            optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
            JButton btnOk = new JButton("OK");
            optionPane.setOptions(new Object[] { btnOk });
            dialog.pack();
            dialog.setVisible(true);
       public static void showMessageDialogUsingStaticJOptionPaneMethod(String message) {
            JOptionPane.showMessageDialog(null, message);
    }Edited by: jduprez on Feb 1, 2010 11:39 AM
    I have to admit, I am a zealous fan of the built-in JOptionPane.showXxx methods :o)

  • Updated to Mavericks, now text is pixelated. How can I resolve this?

    Mid 2010 Mac mini
    Processor  2.4 GHz Intel Core 2 Duo
    Memory  4 GB 1067 MHz DDR3
    Graphics  NVIDIA GeForce 320M 256 MB
    Software  OS X 10.9 (13A603)
    Display Dynex 46" monitor
    I updated to Mavericks today.  When my mini came back online, I had serious display issues that I've somewhat managed to resolve.  The most galring issue is that all text, be it text on a website, text in apps, text of the OS windows, all text everywhere is pixelated.  Glaringly so.  Like 8-bit-style pixelated.  Fuzzy, too.  Can anyone help me understand what has happened and how I can resolve it, please?
    The other display issues I'm having have to do with colour settings and screen resolution.  I've been playing with my monitor settings and the OS settings and none of this has had any affect on the pixelation problem, as far as I can tell.  Selecting "Best for Display" from System Preferences>Displays is the only setting I can choose that doesn't stretch the display beyond the edges of the screen.
    Thank you!

    Hello,
    If 10.7.0 or later...
    Bootup holding CMD+r, or the Option/alt key to boot from the Restore partition & use Disk Utility from there to Repair the Disk, then Repair Permissions.
    If that doesn't help Reinstall the OS.

  • Why is my text jagged/pixelated after rendering?

    Hi
    I am new to motion and I went through a tutorial and I still can't solve this and I'm sure it's simple
    I created some freehand text in motion, exported it and placed it in my FCP time line
    When I play it in the FCP time line it's clean but when I render the line, it becomes jagged and pixelated. I thought rendering would not do that. It's clean in Motion when I create it and play it, it's clean on export in the viewer, it's clean when I drop it in the FCP time line, but as soon as I render the project the text becomes jagged
    Any help is much appreciated
    Thank you
    David
    Message was edited by: skyjamvideos
    Message was edited by: skyjamvideos

    http://www.kenstone.net/fcphomepage/motion_text_in_fcpspencer.html

  • How to use datamerge with variable lengths of text?

    Hello,
    I'm looking for a way to automaticly format brochures from a database . I allready found out that datamerge lets you do this quite easily. But I encounter a problem when I use large amounts of text.
    How I see it, the only solution is to reserve enough space for the larges text in order to make all of the text appear in the document. But this leaves large open spaces and even blank pages in my document when I deal with less text.
    Is there a way to make the document adapt to the amount of text? So that Indesign creates more space for large amounts of text and erases blank pages when there is less text?
    Maybe Datamerge isn't the right solution for my problem, I'm open to suggestions.
    Thanks in advance!
    Iris

    I'm just finishing up a directory that I build with data merge and I have the problem of variable length business descriptions, as well as some have extra mailing addresses or websites. My solution is to do it in several steps with multiple files. I do a normal merge first (and I use a single record per page for this, but only bcause that allows me to create some alphabetical lists of business names and owners's names that I can key to a listing number), then I stitch together the individual stories into a single text thread that I copy/paste into place in the final document. If you have a lot of frames, Rorohiko.com has a nifty text stitch script that will help.
    One tip that helps with this method is to be sure you have a paragraph break at the end of each story so stiching the frames together maintains your paragraphs.

  • Export data as fixed length ASCII text file

    Hi,
    Can someone tell me how to export query data or the data in a table as a fixed length text file. I use PL/SQL developer to query the data.
    Many thanks,

    If you use SQL*Plus, you could try the following.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch7.htm#1007441

Maybe you are looking for

  • E65 and BMW

    I'm able to pair my nokia E65 with my car (BMW Series 5) but I can not see my contacts in idrive. Is there any way to solve this?

  • What is this page?!?

    Stuck trying to restore iPhone. In device page this is the screen I get! Help please?

  • Asynchronous Messages (using JMS) improves performance even when the desire

    I am being told that even when point A to point B communication, originating at point A, is synchronous, send a message to B wait for B to finish processing and send a tagged(to corelate the response to the request) message back asynchronously via an

  • How do i put a photoshop picture on iweb?

    i have a picture in photoshop and i took out the white background so all i see is the checkerboard....when when i add it to iweb it shows white background.....all i want to see is the logo i made itself....with no white background

  • No Event is working on Page

    Hi guys, I have a Adf Page in which i am using region when my page opens no event is firing on it neither row select nor any button click event its my Main Page <?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"