Calculating maximum font size

Okay, I have a JTextField with wrap on. It's setEditable(false). The string in it is going to be changing constantly and the field has a fixed size. I'm trying to come up with a method that will determine the maximum sized font that will be able to fit in the TextField without requiring a ScrollPane.
I'm not quite sure where to start on this one. I'm sure I can come up with a calculation involving font point size and FontMetrics.stringWidth() but I can't figure it out. Any ideas would be helpful.

hi
* Computes a correct font size to use for the text of this component.
private void computeFontSize()
    int height = getSize().height;
    int width  = getSize().width;
    if (current_font != null) //this will be the font the component is currently showing
            // need to create a brand new Font everytime to see if the
            // stringWidth fits into our current width.
            // We can check height by pixels, but sadly need to create a new font
            // for checking the width.
            Font tempFont = new Font(current_font.getName(), current_font.getStyle(), height);
            FontMetrics fm = getFontMetrics(tempFont);
            if (fm != null)
     int textWidth  = fm.stringWidth(getText());
                     if (textWidth > getSize().width)
                            // Text doesn't fit horizontally; scale it down a bit.
                            // (stop div by zero errors)
                            if (textWidth < 1)     
                                     textWidth = 1;
                            int newFontHeight = (height * width) / textWidth;
                            if (newFontHeight != current_font.getSize())
                                  current_font = new Font(current_font.getName(), current_font.getStyle(), newFontHeight);
                     else if (tempFont.getSize() != current_font.getSize())
                           current_font = tempFont;
           tempFont = null;
           fm = null;
}this code was taken from a homegrown label component that scales its own font based on its size.
There is enough here for you to work out what you need.
If it meets your needs, don't be shy with the dukes
nes

Similar Messages

  • Maximum font size for auto-sized form text

    You need to let the user select a maximum font size for automatically sized text. If most of your fields are set at 10pt type, but you have one field for which you want the text to resize automatically, it looks stupid if that cell contains a small amount of text that’s set at 16pt or whatever. If you could set the maximum font size to 10pt for that field, then the text would be consistent with the text in the other fields unless there is so much text that it needs to scale down.

    Can anyone please advise?
    Cheers

  • Set maximum font size

    Is there a way that I can set the maximum font size?  I want to limit the size of all fonts.

    I found tinkertool, which did exactly what I wanted.  I love it.
    http://www.bresink.com/osx/0TinkerTool/download.php5

  • Maximum font size in a finder window

    Hello,
    I'm trying to increase the font size in ONE finder window, so that my wife with decreased mobility can read the text on a TV screen.
    In view options, the maximum is 16 pt. Is there any way to increase this? I do not want to increase the size in other windows.

    AFAICT, no. You could try lowering the display's resolution and see if that'll help. Alternatively, turn zoom on in Universal Access prefPane, zoom, and see if that works.

  • Maximum font size?

    I am unable to get text larger than fontSize=127 with Flex.
    This limitation doesn't exist in Flash, what am I missing with
    Flex? This is a pretty huge problem for what I was doing.
    The whole text/font system seems to be lacking. Many font
    families don't seem to render with flex and default to one of the
    serif/san-serif fonts. Several fonts suffer from clipping at the
    end when fontStyle=italic. Neither the case in Flash.
    Thanks

    Hi,
    Did any of you two got a confirmation that this is a
    limitation in Flex?
    I seem to be having the same problem, and since our interface
    design requires a font size of 152 pixels, this looks like a
    serious problem for us.
    Regards,
    Arjan

  • Maximum font size script

    Howdy all!  Have a tricky question. Using LiveCycle ES 8.2
    Working on a form, I've got a pair of linked text fields (global data linked).
    These text fields are static in size, but I need the values typed into them to shrink when it fills up the visible area of the text field.  I can't set the value font size to 0pt from the start.  It makes the initial font size too big for the value.  The font size needs to remain at 16 pt until the value fills up the field's visible area, then it needs to switch over to 0pt (hence triggering a full event).
    I've tried using a full event with the following code;
    this.font.size = "0pt";
    But it won't fire.  I wonder if there is a limitation to the what the full event can trigger.  I can use the change event or even the exit event if I have to.
    I've also tried a calculate event with the following script:
    if (this.rawValue.length > 48) {
         this.font.size = "0pt";
    else {
         this.font.size = "16pt";
    But this did not fire as well.  And yes, I have the scripting set to Javascript...not Formcalc.
    Any suggestions?

    Hi,
    Using ES3 and just a 0 font initially (with all scripting removed) I get the following, for a short name;
    Which seems about the right.
    And for a long name
    My version of your form is here https://sites.google.com/site/livecycledesignercookbooks/home/bizcard_form.1.pdf?attredire cts=0&d=1
    There have been some changes since ES8, including a default font size added to the form properties, but not sure that is a factor as the largest font used in this sample is still smaller than the default.
    Is this what you are seeing?
    Bruce

  • Auto text font size

    Is there a way to set a text box so it keeps all the letters within the box at the maximum font size?
    for example:
    set a box 4x1 inch
    type a 4 letter name and from the start of the first letter to the end of the last letter be 4 inches
    then type an 8 letter name and from the start of the first letter to the end of the last letter be 4 inches again.
    My Dymo label maker software can do this. surely illustrator can too!
    if not, is there any scripts / alternatives?
    Thanks!!

    Jamie,
    Sorry, now I believe I understand.
    Unless you actually need a box, you may create the text as noermal live Type, then in the Transform palette set the desired W (width) value and Ctrl/Cmd+Enter to keep proportions.
    If you need a box, you may:
    1) Create the Type normally;
    2) In the Appearance palette flyout click Add New Fill/Stroke, depending on which kind of box you want;
    3) Drag the new Fill and/or Stroke down beneath the Characters in the main Appearance palette window and set the desired Color(s) and possible Stroke Weight;
    4) Effect>Convert to Shape and tick Rectangle, then set the Relative>Extra Weight/Height as desired (maybe 0), depending on how much you want it larger than the Bounding Box (you may set a positive value for Weight and 0 for Height);
    5) In the Transform palette set the desired W (width) value and Ctrl/Cmd+Enter to keep proportions.

  • Max font size on 'auto' size

    I've multiple lined text fields in the pdf document. I want the input to be resized if it exceeds (selected auto font size in properties) but I also want the first font size to be '10 pt'.
    When I select auto, it chooses the maximum font size to fit in the box, I want the upper limit to be fixed at 10 and it gets smaller if text exceeds the box size.
    How can I do that ?
    Acrobat Professional XI

    For multiline text fields, it seems the initial size is 12 when the font size is set to Auto. You don't have control over this, unfortunately.

  • Maximum database size Exchange 2013 Standard

    Hi,
    Does anybody is aware of database size limitation for Exchange 2013 Standard. I remember in older version there was a registry tweak to increase database limits.
    Thank you 
    alfa21

    Hi,
    This is the official answer :
    Supported: Approximately 16 terabytes.
    Best practice:
    2 terabytes or less.
    Provision for 120 percent of calculated maximum database size.
    https://technet.microsoft.com/en-us/library/ee832792%28v=exchg.150%29.aspx
    Cordialement,
    Mickaël LOPES
    Blog : http://lopes.im 
      

  • How to change font size, maximum column size in the result screen ?

    hi All
    That's great when using SQL Dev.
    But I also have a trouble that how to change font size, maximum column size in the result screen ?
    My users think that font in result screen is shown very small, and whenever the data in each colum is long then it's not shown full data in column, they must double click for extend the size. Have the option to default the max size for showing full data in each column ? I try but still not to do that .
    Appreciate for anyone to help us.
    Thanks all.
    Sigmasvn

    You can't change the font for the results screen yet, however you will be able to select an auto-fit option for selected columns, so if some columns have slitghtly wider text you'll be able to set the column widths to handle these wider columns.
    Also, there s the option of switching the layout of a record in the grid.
    Sue

  • How is the font size calculated in pixel sized documents?

    Hello to all,
    I am working with Illustrator CS4 on a web design. In the document setup, I set the size to 1000*1600 pixels. Then, I tried to add some text in font size 12 pt. The font appears *very* small. My objective was to use the same font size settings in my Illustrator file as I will later do in the HTML/CSS coding. How do I get Illustrator to scale the fonts in the same way as the browser does - i.e. a 12 pt text in the browser has the same size as a 12 pt text in Illustrator? Infact, I am looking for a setting where I can define the resolution of text size calculation.
    Best regards
    Joerg

    Illustrator is a print-oriented, object-based vector drawing program, not a web-oriented, pixel-based raster painting program.
    Illustrator's ruler is designed to represent real-world measure, not counts of pixels.
    A pixel is not a measure. Pixels have no real-world measure.
    Therefore, when Illustrator's ruler pretends to represent "pixels," it has to assign some real-world scale to them. It defaults to the measure of a point. A point is a real-world measure.
    Similarly, a computer's operating system has to decide how many screen pixels it will use to represent a real-world measure at 100% zoom.
    Mac OS defaults to using 1 pixel to represent 1 point. (72 PPI)
    Windows and web browsers default to using 1.33 pixels to represent 1 point. (96 PPI)
    So tell a browser to display 12 point type, and it will use 16 pixels to do that.
    Given Illustrator's default that 1 pixel measures 1 point at 100%, Illustrator uses about 9 pixels to render the cap height of 12 point Verdana.
    GIven the browsers' default that 1 point renders to 1.3 pixels, the browser uses about 12 pixels to render the cap height of 12 point Verdana.
    So given that Illustrator and the browser are going to use different numbers of pixels to rasterize 12 point type, how do you get a browser to use the same number of pixels to render 12 point Verdana as Illustrator does? Simple: Specify the type size in the HTML code by pixels, not by points. This is a screenshot of Internet Explorer on Windows displaying a web page which contains:
    A raster image of 12 point Verdana exported from Illustrator, using its default 72 PPI rasterization
    Live 12 pixel Verdana HTML text.
    Live 12 point Verdana HTML text.
    Inversely, there are other ways to work around Illustrator's 72 PPI default when you want to rasterize Illustrator type so that it looks the same as the same-point-size text in HTML.
    When using Save For Web & Devices, specifiy 133% instead of the default 100%.
    Scale the artwork to 133% before exporting via Save For Web & Devices using the default 100%
    When rasterizing, rasterize to 96 PPI instead of 72 PPI. (1.33 as many pixels)
    When exporting, export to 96 PPI instead of 72 PPI. (1.33 as many pixels)
    Or, do what I do: Get a decent screenshot utility. When I want to rasterize something from Illustrator that contains text that I want to appear online at the same scale that it appears to me when working in Illustrator, I simply zoom to 133% and take a screenshot.
    JET

  • Font size dependent text item size calculation

    Hello there always helping hand !!
    I have a requirement like this
    1. Depending on the Form Co-ordinate system
    2. Depending on the Font name and size of the Text Item
    3. For a multiline text item
    4. Given the context string to display in it
    I want to calculate the optimal width and hight for that text
    item.
    Please give me sugestion on the calculation formulae and or
    pointer to the detailed discussion....
    Thanking you in anticipation
    Santosh
    [email protected]
    null

    >
    Naresh Kumar Malik wrote:
    > Hi
    >
    >
    >
    >
    > You can use <h1> HTML tag. Here
    > concatenate   '<h1>'  item_eform_reqno '</h1>' into head.
    >   wd_context->set_attribute( exporting name = 'EFORM_HEAD' value = head ).
    >
    >
    > Here attribute EFORM_HEAD is bounded to the text view element.
    >
    > Regards
    > Naresh
    This should NOT work!  The UI elements should safe encode all input values - thereby eliminating the value of any HTML tags. If you system isn't doing this already then it is a bug and if you rely on such a thing it will stop working at some point in the future.
    You are basically restricted to different values available via the design parameter.  The overall font sizes come from the underlying themes and the client applications (browser or NetWeaver Business Client) that host the Web Dynpro Application.  Therefore no direct specification of the font size is possible in order to stay within the controls of theme.  If you don't like any of the designs available, you might consider altering the Portal Theme you are using - but that is a rather drastic approach.

  • How can I change the font size and placement of photo descriptions in an  iPhoto slide show?

    With an iPhoto slide show, how do I change the font size for titles and descriptions and position the text when preparing a slide show?

    to change the pixels crop to 100x100 and export with maximum dimension of 100 - see the user tip on exporting foo details on Export options - Exporting From iPhoto
    As to DPI - digital photos have no DPI since DPI is Dots Per Inch and digital photos have no inches hence no DPI - when you print a photo then DPI is a mathematical calculation - dots divided by inches - it is not a setting
    Print a 480 pixel photos as a 1" square and the print it 480 DPI (480 / 1 = 480) and print the 100 pixel image as a 1" square it will be 100 DPI (100 / 1 = 100) - print a 480 pixel photo as a 4.8 inch square and it is 100 dpi (480 / 4.8 = 100) - just a calculation - not a setting
    LN

  • After the recent update the entire browser, including menus, icons, and everything on the web page, are too small. Fonts are smaller, pics are smaller, zoom settings will not remain universal. Minimum font size will make text readable, but all pics are to

    The new update has screwed up my browser settings, I cannot get them fixed and Im pissed because my computer is an eye-sore to read until this is fixed! EVERYTHING in the browser is smaller, fonts, menus, icons, web page content, pictures, tables, etc. I have set the minimum font in the settings and the text is just to a point where it is easily readable at the maximum size setting, but all the menus and icons are still tiny and hard to read. The last version I had installed worked fine with no add-ons needed. Everything fit the screen fine and was easily readable without modification. I want this version off my PC and I want the last version I had back on but I dont know what version it was!!!!!!! ARARGGGG
    In fact, this stupid troubleshooting window that I am in filling out this form doesnt fit the page right at all, and edges of the text are cut off, so Im not even sure what some of these boxes are asking for!!

    See [[Toolbars and page content appear too large after upgrading to Firefox 3]]
    *Try to adjust the DPI setting, see http://kb.mozillazine.org/layout.css.dpi
    *Try to set the pref layout.css.devPixelsPerPx to 2 on the about:config page.
    To open the ''about:config'' page, type '''about:config''' in the location (address) bar and press the Enter key, just like you type the url of a website to open a website.
    If you see a warning then you can confirm that you want to access that page.
    If you need to increase (or decrease) the font size on websites then look at:
    Default FullZoom Level - https://addons.mozilla.org/firefox/addon/6965
    NoSquint - https://addons.mozilla.org/firefox/addon/2592

  • Maximum text size for textFormat

    Afternoon everyone,
    I am working on an application in which text is created
    dynamically. I seem to be experiencing a maximum size of 130 when
    using textFormat. I cannot seem to find any references to this
    limit. Is there a way to get around it?
    So far my only resolution is to create a smaller text field
    within a movieClip and then scale the movieClip. This moves the
    text of the pixel location that I need it however.
    Any help with this would be very much appreciated.
    Cheers,
    Michael

    you can making the text html and setting the text like this:
    <font size="X">text</font>
    Otherwise, if you can't set a font bigger tahn 130, you'll
    have to resize movieclips.
    You can create a custom class that embeds aTextField within a
    movieclip so that you get transparent coding, just replace
    TextField with CustomTextField.

Maybe you are looking for

  • Transferring Specific Playlists From One Mac to Another

    I just bought a MacBook Air and would like to transfer certain files/folders/applications from my MacBook to my MacBook Air using Migration Assistant. I know that it is possible to transfer iTunes playlists using Migration Assistant, but I don't know

  • 244 random photos suddenly appeared in the wrong folder

    I recently imported 8 photos into Lightroom 5.7 using the "2015-05-25 Folder Name" naming system, and I saw the 8 imported photos in the folder. No problems. However, after reopening Lightroom, the folder with 8 photos suddenly has 252 photos. There

  • HT204135 I can't get my HP 4500 510g printer to install correctly on my iMac with OSX 10.8.4.

    I tried installing with HP software & it will print a test page from the HP utility but not from any applications. I then tried to install using "add printer" and got a message "no software available". After checking apple.com I learned that I should

  • RGB Colors

    I have a RGB-color and I want to make it a little bit brighter or darker. First I tried out the two functions java.awt.Color.brighter() and darker(), but I noticed that both functions turn a random color to white in a few steps. Therefore I tried to

  • How do I reset or better yet get rid of security questions

    I followed the posted suggestions but it asked me to answer two security questions to continue which I think is stupid because that's my problem... Can someone help?