Getting the height of a font

Hi there,
I have a problem in determining the exact height of a font.
I am using a JPanel to display some text in a GUI. The panel should have space for five lines of text. How can I determine the size of the font before the Frame that is containing my GUI is shown, so that I can set the size of the JPanel to the appropriate size?
I've tried
FontMetrics metrics = getFontMetrics(getFont());
int lineHeight = metrics.getAscent() + metrics.getDescent();
But this produces a NullPointerException on runtime.
Does anyone know another way to get the height of a font before the frame is shown?
Thank you,
FReAK

Ok,
I figured out that the problem is that getFont() gets null as font.
So if I use setFont() everything is fine.
But I don't have to set a specific Font when drawing a String, so is there must be a standard Font.
Does anyone know how to get the metrics of this font?

Similar Messages

  • Is there any way to get the height/width of an image before importing it in the indesign document.

    Hi All,
    I need to obtain an image's attributes such as dimensions (height, width in pixels) without placing image in indesign document.
    I have full path of the image (say abc.jpg is stored at c:\my pic\abc.jpg).
    I have obtained the IDFile for this image, tried getting size using GetFileSize() which correctly return size in bytes.
    Is there any way to get the height/width of image without importing it in the indesign document.
    Please, give me some hints. I have spent quite a lot time digging in CHM. I have searched in FileUtils, IDFile API's but found no method which serves this purpose.
    At this point I am clueless where to search next.
    Any help will be appriciated.
    Just a point to mention, I am able to get image height and width for an image in indesign doc though Its not my requirement.
    Thnx,
    D.

    You might be able to examine the contents of the PlaceGun after calling kImportAndLoadPlaceGunCmdBoss without actually placing the image in a document. Not sure, but would be worth looking at.
    Otherwise you will probably have to write platform specific code, ideally with a generic platform-independant wrapper (see SDKSamples/paneltreeview/PlatformFileSystemIterator).
    For the Mac, look at CGImageGetWidth() etc., not sure what the best option is for windows.
    Perhaps Quicktime could provide you with a platform independant solution.

  • Get the "cannot extract embedded fonts" error message

    I get the "Cannot extract embedded font 'UZNVZW+HElveticaNeueLTStd-Hv-Identity-H'. Some characters may not display or print correctly." error message when I generate a PDF from MadCap Flare or Frame Maker. I am on Windows 8 64-bit / Adobe Acrobat 11 / FrameMaker 9 / MAdCap Flare 9.
    When I do the same task on a Windows 7 system, works like a whistle.
    I am looking at a solution and no workarounds.
    Regards,
    AxDe

    Hi hartmanja14,
    Please let me know if this is happening with all PDFs or any specific document?
    Also, tell me if that document has been created by any third party or not.
    Regards,
    Anubha

  • How can I get the height of an UIComponent programmatically?

    How can I get the height of an UIComponent programmatically? In my case the component is a Panel Box which has bindings to a backing bean. But it seems the RichPanelBox does not have have method like getHeight()

    Use setInlineStyle(java.lang.String inlineStyle) method.
    RichPanelBox panelBox;
    panelBox.setInlineStyle("height:400px");
    Thanks,
    Navaneeth

  • Getting the height of the title bar of a JInternalframe

    Hi,
    How can i get the height of the title bar of a JInternalframe??
    Please reply asap.
    Thanks
    Jatin

    Try this.
    myFrame.getUI().getNorthPane().getHeight();

  • Getting the Height of Android Status Bar

    Hello,
    is it possible to get the Height of Android Status Bar ?
    thanks

    Hi Shongrunden,
    The above solution will not work when testing on the desktop as Capabilities.screenResolutionY returns the actual screen resolution of the host machine and not that of the emulated device.
    I too would really appreciate a method to obtain the devices status bar height (i.e Capabilities.statusBarHeight) for calulating component width and height upfront.
    Regards,
    Scott.

  • Get the height of a report to use for setting height of subreport

    I am getting an error:  Invalid Section Height   on one of my subreports
    that I am programmatically inserting into a report.  I have not set the
    subreport height, I thought that it would be automatically set if I didn't
    set it.   I am measuring the width of a section in the report I am using
    for a subreport to use as the Width for the subreport, but not sure how
    to get the height of the report.   It appears this needs to be in pixels.
    I have manually tried setting it to 14400, which I believe is 11" and I ge an invalid section height error.
    How do I get the height for the subreport???  
    I am using VB.Net 2008, Crystal 2008, Vista Buisiness.   - All the latest service packs of everything.
    Thanks,
    Jeff

    Hi Jeff,
    The easiest way to figure this out is to test it in the Crystal Reprot Designer first. Bascially you can't set the subreport higth larger than the report page itself. CR needs to allocate space for the Page header and footer then Group header/footer and detail sections. There are options when designing this in CR Designer which will allow you to span more than one page. The simplest way is to design a template report in Crystal Report Designer so you can see all the options required to make this work. Then you can set the same in code when inserting.
    Remember "If it can't be done in the Report Designer it can't be done in code" The Designer uses the same set of API's as .NET. By using a test report you can then see what settings are being configured when you get the info in code.
    It believe you simply need to set the Can Grow options. Test this in the Designer then update us if you have any more questions.
    Thank you

  • Problem getting the height of a UIScrollView

    hi,
    i am setting the size of a UIScrollView in viewDidLoad: but when I try to get the height of it, i am getting 0 in the console
    here is my code:
    - (void)viewDidLoad {
    [scrollView setContentSize:CGSizeMake(320,500)];
    NSLog(@"scrollView: %@", scrollView);
    NSLog(@"scrollView.contentSize.height: %i", scrollView.contentSize.height);
    [super viewDidLoad];
    and in the console log i get
    scrollView: <UIScrollView: 0x4974110; frame = (0 0; 320 367); clipsToBounds = YES; autoresize = RM+TM; layer = <CALayer: 0x4974010>>
    scrollView.contentSize.height: 0
    Shouldn't scrollView.contentSize.height be returning 367? On a related note, i specified the height to be 500 via [scrollView setContentSize:CGSizeMake(320,500)] , but that doesn't appear to be applied either?

    The width and height of CGSize are CGFloat type (double), so use a float format specifier in NSLog. E.g.:
    NSLog(@"scrollView.contentSize.height: %2.0f", scrollView.contentSize.height);
    - Ray

  • How to get the height of JPanel?

    Hi.
    I am new to GUI programming.
    I am trying to get the height of a JPanel which I put inside a JFrame but the getHeight() method returns me zero.
    My code are as follows:
    public class Form2
    public static void main(String[] args)
    JFrame f = new JFrame();
    JPanel p = new JPanel();
    f.setTitle("Testing...");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 300);
    f.setVisible(true);
    f.add(p);
    System.out.println(f.getHeight());
    System.out.println(p.getHeight());
    Can somebody enlighten me on how to obtain the height of the JPanel?
    Thanks in advance.

    Swing related questions should be posted in the Swing forum.
    I am trying to get the height of a JPanelComponents don't have a size until the JFrame is made visible and all the components are layed out by the LayoutManager. You can use a WindowListener to tell when a frame is shown.

  • Who to get the height of the text in a Text Layout?

    Hey, I'm using the text layout component offered by adobe labs. I read the documentation and now capable of doing almost all what I need. I just have a small problem. Lets say I have a text layout object on my stage containing some text. How can I know the height of the text or the number of lines in it ???
    I found their is a porperty: "contentHeight"  and a method "calculateHeight()" but they are in another class of the libraries that comes with the text layout component. I don't know how to reach them. Please help and write me the lines of code that do this job.
    Thanks

    Well I was going to suggest that you post in the TLF forums, http://forums.adobe.com/community/labs/textlayout.
    But you seem to have found those. So instead I will suggest that you don't cross-post.
    Really if anybody could answer that it would be the folks there. I know there isn't a lot of traffic in those forums, but that is because the TLF is really insanely complicated and it is still beta. But it looks like most questions there do get some kind of answer....

  • Getting the height of a binary tree

    So I am trying to create a method in my binary tree class that returns and integer that represents the height of the tree.
    I tried to do this recursively and it seems the numbers are close to the actual ones, but never exact and I haven't really been able to find out where the problem lies. This is my code:
    public int getHeight()
              int height;
              height = getHeightRecur(root);
              return height;
         public int getHeightRecur(BinTreeNode node)
              int theight;
              if(node == null)
                   theight = 0;
              else
                   theight = 1 + getMax(getHeightRecur(node.leftN), getHeightRecur(node.rightN));
              return theight;
         private int getMax(int x, int y)
              int result = 0;
              if(x>y)
                   result = x;
              if(y>x)
                   result = y;
              return result;
         }

    j2ee_ubuntu wrote:
    it may help at some extent..
    private int getMax(int x, int y)
              int result = 0;
              if(x>y)
                   result = x;
              else if(y>x)
                   result = y;
    else //when both are equal
    result =x; OR result = y;//You can use one of them
              return result;
         }Edited by: j2ee_ubuntu on Nov 6, 2008 12:30 AMWhy not just use [ Math.max|http://java.sun.com/javase/6/docs/api/java/lang/Math.html#max(int,%20int)] or write
    public static int max(int a, int b) {
        return (a >= b) ? a : b;
    }

  • How to get the PDF Text position, font, size, align...?

    Hi~!
    I can extract all the text from the PDF file, but just plain text.
    I need their format, position, font, size, align.
    I am using C#, IAC, and read the SDK carefully.
    How to get them?
    Thanks for every hint on how to achieve this!
    Jason Wang

    "Often this is a rectangle, sometimes not (e.g. for italic text the box
    may be slanted too)."
    Sometimes it lines up with the horizontal axis, sometimes not.
    Aandi Inston
    =====================================================
    "Remember, in PDF, the origin is BOTTOM LEFT... "
    Leonard Rosenthol
    =====================================================
    Thank you, Aandi, Leonard, Thanks a lot
    Jason Wang

  • How to get the actual font name from a font file?

    Hi
    I have only the font Path I have to get the font name from that path. Any idea how to get the actual font name?
    Thanks,

    I would ask you these questions:
    Why do you need to do this?  What are you ultimately trying to accomplish?
    Are you really asking about the InDesign SDK?
    Do you really need to get the "name" of a font from an arbitrary file?  Or do you want information about a font installed on the system?  If so, what OS?
    Do you need to be able to handle any font format?
    Which font "name" do you mean?
    What language do you want the name in?
    (1) It's not clear what you're trying to accomplish.  A bit more information about your ultimate goal would be helpful.
    (2) This question is not at all specific to the InDesign SDK.  Are you really trying to do something in the context of an InDesign plug-in?  If so, you probably want to look at IID_IFONTFAMILY and the IFontFamily::GetFamilyName function.
    (3) If you are asking more generally, Windows and Mac both have system API calls to get this information, although those tend to deal with installed system fonts, not with arbitrary font files per se.
    Also, you can parse the name table from a True Type or Open Type font without using any system APIs; as True Type and Open Type are well-documented standards.  I would start by reading these:
    The Naming Table
    Font Names Table
    (4) Although there are other standards, such as Type 1 (PostScript) fonts, and True Type Collection files and other formats, especially on Mac.
    (5) Also, when you start down this road, you will quickly realize that your seemingly simple question is actually ambiguous, and that the answer is kind of complicated, because a font can have many names (a family name, a full font name, a style name, a PostScript name, etc.).
    (6) And not only does a font have multiple names, it can have each of those names in multiple languages and encodings.
    Any clarification would make this a better question.

  • How to set the size of a Font in Pixel?

    Hi,
    i know how to get the screen resolution of the current monitor and I know how to use Fonts (and I know how to read the API, but that didnt help).
    Is there a way to set the size (or at least the height) of a Font in pixel rather then in points?
    All I actually need is how many pixels the height of my String will be when I print it on the screen.
    I use Swing and drawString(...) to draw my String (this information shouldnt matter, but just in case).
    thanx

    Hi,
    search doc about FontMetrics, you'll find infos about how to get the font height... If I remember well, you need to get the Graphics of the component, then call getFontMetrics() or getFontMetrics(font) to obtain the metrics, then call getHeight() to know the font height...

  • How to get the page break preview in java

    I have an in house report building utility using gridbaglayouts. My reports are coming pretty good but i am unable switch the grids page wise. I tried using the graphics but failed as it cuts the grid in between. The grid bag layout does not return and size(height and width) for the grids. so theoption of getting the heights of grids will not work. Please give me the solution

    j0o wrote:
    System.out.println("Class Name: " + new Exception().getStackTrace()[0].getClassName() +
    "/n Method Name : " + new Exception().getStackTrace()[0].getMethodName() +
    "/n Line number : " + new Exception().getStackTrace()[0].getLineNumber());
    I pointed the OP at this approach yesterday in one of his multi-posts. I still have not been given my Dukes!

Maybe you are looking for

  • How do I tell if a radio button is selected?

    Apart from relying on the radiohandler, is there any direct command or code which i can use to immediately check if a particular radio button is selected or not? Like in Visual Basic, we can immediate state if (radiobutton.value = false) is there any

  • How can I put my iPod's songs into my pc?

    Hi!I bought my iPod in November and this week I putted all the music which was in my PC into my iPop, and there is a thing I don't understand: how can I do to put my iPod's music into my PC? I'll be really pleased if you asnwer my question!bye

  • JRA in MII 12.1.3 Build(65)

    Hi, I am working with JRA actions for the first time. I am not sure if this is maintained in the configuration or elsewhere. I don't see in the JRA Start Session where to supply the SAP Client, Username and Password values? This is unlike MII 12.0. R

  • How do you relink video from low res to high res and keep audio synced?

    Hello, I'm trying an offline to online workflow but my synced audio from my offline clips are not transfering to my online clips. Anyone have a solution?

  • PI 2.2 Monitoring Policies

    I have created port groups and used the criteria of description used on network interfaces to categories the interfaces into functions, WAN facing, Internet facing etc. I was hoping to then create Monitoring Policies to then use for each of the port