4 Replies Latest reply on Jun 18, 2009 7:42 AM by 843851

    Something like fontmetrics??

      Hello, i'm trying to make a new component, a scrolltext. I see in other post, the correct way to make it, with a HContainer and HText. It works perfectly but i want improve it. I'm trying the vertical size ajdust automatically, I'm using a DVBTextLayoutManager object and TextOverflowEvent, but isn't efficient. I tryed to use the FontMetrics object, but when I use Toolkit.getDefaultToolkit().getFontMetrics(usedFont); in the HContainer, i get a NullPointerException, I suppose the method is not implemented. Anyone knows how I can obtain the vertical lenght of a text, to fit atumatically the HText component???
        • 1. Re: Something like fontmetrics??
          Hi! All
          To design Scrollable text you can use HComponent class. You need to first define default font for the component, now override paint method. set font and forecolor to graphics object and use drawString method to paint text on the component. to paint text you need to divid you text into string array according to the width of component, for that you can use FontMatrix object which will give you the character height and with leading spaces. when you break you string find out height of component and show that no. of string. On key event you need to increase or decrease the line no of string array and call the repaint method so it will look like scrollable text box.

          Edited by: Buddhdev.Sahu on 16 Jun, 2009 3:16 PM
          • 2. Re: Something like fontmetrics??
            I have designed a Scrollable text, but the FontMatrix class doesn't exists, and the FontMetrics class doesn't work, it throws a NullPointerException when I call it. I'm searching for another way to get the height of the font
            • 3. Re: Something like fontmetrics??
              i have come across different mhp stub and thay have FontMatric class inside java.awt package or you can also get the instance through the Toolkit class. To get the reference of font matric class you need to first set the font for current componet from where you want to get the FontMatrics class instance. you can try this code to get reference of FontMatric class.
              public void paint(Graphics g) {
                        Font f = new Font("Arial", Font.PLAIN, 26);
                        FontMetrics metrics = this.getFontMetrics(f);
                        //          metrics = Toolkit.getDefaultToolkit().getFontMetrics(f);
                        g.drawString("Hello! How are you?", 50, 50);
              • 4. Re: Something like fontmetrics??
                thank you! if i try to get the fontmetrics using Toolkit class, it doesn't work. But when i used the HVsible method getFontMetrics, it works perfectly.