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

Similar Messages

  • Search Text in a TextBox using IndexOf

    Rather than using Regular Expression I want to know how I can use LastIndexOf and IndexOf to search for the Next and Previous match of a word typed. I want to use a TextBox and not a RichTextBox. Can someone provide me with a way to do this using loop so
    it gets all the matches. I've got this so far:
    Public Function FindAndSelect(TextToFind As String, MatchCase As Boolean) As Boolean
    Dim mode = If(MatchCase, StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase)
    Dim position As Integer = textBox1.Text.IndexOf(TextToFind, mode)
    If position = -1 Then
    Return False
    End If
    textBox1.SelectionStart = position
    textBox1.SelectionLength = TextToFind.Length
    TextBox1.Select()
    Return True
    End Function
    MessageBox.Show("Hey You!")

    Rather than using Regular Expression I want to know how I can use LastIndexOf and IndexOf to search for the Next and Previous match of a word typed. I want to use a TextBox and not a RichTextBox. Can someone provide me with a way to do this using loop so
    it gets all the matches. I've got this so far:
    Public Function FindAndSelect(TextToFind As String, MatchCase As Boolean) As Boolean
    Dim mode = If(MatchCase, StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase)
    Dim position As Integer = textBox1.Text.IndexOf(TextToFind, mode)
    If position = -1 Then
    Return False
    End If
    textBox1.SelectionStart = position
    textBox1.SelectionLength = TextToFind.Length
    TextBox1.Select()
    Return True
    End Function
    MessageBox.Show("Hey You!")
    Hello,
    For Next, we could get that done with following way since we could select start index, you could refer to
    String.IndexOf Method (String, Int32, StringComparison).
    Dim startPostion As Integer = 0
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim str As String = "1"
    ' Dim mode = If(StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase)
    If startPostion + str.Length > TextBox1.Text.Count Then
    Return
    End If
    Dim position As Integer = TextBox1.Text.IndexOf("1", startPostion, StringComparison.CurrentCultureIgnoreCase)
    If position = -1 Then
    Return
    End If
    TextBox1.SelectionStart = position
    TextBox1.SelectionLength = str.Length
    startPostion = position + str.Length
    TextBox1.Select()
    End Sub
    The part about previous is quite similar, you could edit it to suit your scenario.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Vertical text in Excel output

    Hello,
    I am designing a report with Excel output using BI Publisher. The problem i am facing is that the text direction (vertical) in the RTF file does not remain the same in the Excel output. Do you have any solutions/workarounds for this problem?
    Thank you.

    Hi Radu,
    I'm afraid, I'm not able to do it, somehow although excel has the option to rotate text by any angle, it does not seem to accept the text direction that RTF does..
    -Domnic

  • Alv output using oops for numc field

    Hi,
    iam displaying alv output using oops.
    one of output field data type numc and length 4.
    in field catalog  i set lzero = 'X'.
    now data is coming with leading zero. if data contains 0000  i want blank value in report output.
    i tried with no_zero = 'X'  blank values are display but leading zero are not display for other values.
    how can i change the code.
    Regards,
    Suresh.

    You will have to use data type char in your case.
    regards,
    Advait

  • Formatting output using XSL

    Hi All,
    Here is my XML output from an XSQL file.
    <ROWSET>
    - <ROW num="1">
    <EMP_NAME>Employee A</EMP_NAME>
    <WEEK_NUM>3</WEEK_NUM>
    <NOOFDAYS>5</NOOFDAYS>
    </ROW>
    - <ROW num="2">
    <EMP_NAME>Employee A</EMP_NAME>
    <WEEK_NUM>4</WEEK_NUM>
    <NOOFDAYS>5</NOOFDAYS>
    </ROW>
    - <ROW num="3">
    <EMP_NAME>Employee A</EMP_NAME>
    <WEEK_NUM>5</WEEK_NUM>
    <NOOFDAYS>5</NOOFDAYS>
    </ROW>
    - <ROW num="4">
    <EMP_NAME>Employee B</EMP_NAME>
    <WEEK_NUM>4</WEEK_NUM>
    <NOOFDAYS>5</NOOFDAYS>
    </ROW>
    - <ROW num="5">
    <EMP_NAME>Employee B</EMP_NAME>
    <WEEK_NUM>7</WEEK_NUM>
    <NOOFDAYS>5</NOOFDAYS>
    </ROW>
    - <ROW num="6">
    <EMP_NAME>Employee B</EMP_NAME>
    <WEEK_NUM>9</WEEK_NUM>
    <NOOFDAYS>4</NOOFDAYS>
    </ROW>
    - <ROW num="7">
    <EMP_NAME>Employee C</EMP_NAME>
    <WEEK_NUM>3</WEEK_NUM>
    <NOOFDAYS>2</NOOFDAYS>
    </ROW>
    - <ROW num="8">
    <EMP_NAME>Employee C</EMP_NAME>
    <WEEK_NUM>4</WEEK_NUM>
    <NOOFDAYS>5</NOOFDAYS>
    </ROW>
    - <ROW num="9">
    <EMP_NAME>Employee C</EMP_NAME>
    <WEEK_NUM>7</WEEK_NUM>
    <NOOFDAYS>4</NOOFDAYS>
    </ROW>
    So I am getting XML in form of:
    Employee A: Week 3: Noofdays : 5
    Employee A: Week 4: Noofdays : 5
    Employee A: Week 5: Noofdays : 5
    Employee B: Week 4: Noofdays : 5
    Employee B: Week 7: Noofdays : 5
    Employee B: Week 9: Noofdays : 4
    Employee C: Week 3: Noofdays : 2
    Employee C: Week 4: Noofdays : 5
    Employee C: Week 7: Noofdays : 4
    And now I need to generate and output in Cross tab format where Employee is in X-axis and Week is in Y axis. Now my XML does'nt contain information for all the weeks and I want to display 0 in the cell wherever the week is not applicable and the appropriate noofdays in the cell where information is there.
    So my output looks like this:
    Empl Name 1 2 3 4 5 6 7 8 9 10
    Emp A 0 0 5 5 5 0 0 0 0 0
    Emp B 0 0 0 0 5 0 5 0 4 0
    Emp C 0 0 2 5 0 0 4 0 0 0
    How can I generate such output using XSL. I even tried <xsl:key> but its not working fine. Can anyone have any ideas for generating such output using xsl.
    Any help in this will be highly appreciated. Its bit urgent...
    Thanks

    Hi All,
    Well I got the solution for this. The exact XSL for generating Crosstab report is as follows:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:key name="x" match="ROW" use="ROWS"/>
    <xsl:template match="/page">
    <html>
    <center>
    <body bgcolor="#FFFFFF" text="#000000">
    <table width="75%" border="1" style="background-color:#F5DEB3">
    <th style="background-color:#BBBBBB">Employee Name</th>
    <xsl:for-each select="ROWSET/ROW/COLH">
    <th style="background-color:#BBBBBB">
    <xsl:value-of select="."/>
    </th>
    </xsl:for-each>
    <xsl:for-each select="//page/ROWSET/ROW[generate-id()=generate-id(key('x',ROWS))]">
    <xsl:variable name="currow" select="ROWS"/>
    <tr>
    <td><xsl:value-of select="$currow"/></td>
    <xsl:for-each select="//page/ROWSET/ROW/COLH">
    <xsl:variable name="curcol" select="."/>
    <td align="center">
    <xsl:for-each select="/page/ROWSET/ROW[ROWS=$currow]">
    <xsl:if test="$curcol=COLS">
    <xsl:value-of select="CELLS"/>
    </xsl:if>
    </xsl:for-each>
    </td>
    </xsl:for-each>
    </tr>
    </xsl:for-each>
    </table>
    Back
    </body>
    </center>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    I hope this will help others.
    Thanks
    null

  • 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

  • TS5180 I get no sound when someone text me like I use to, any ideal as to what happen

    no sound when someone text me like it use to do any ideal as to what happen

    Hello tiffay8,
    Thanks for using Apple Support Communities.
    From your post I understand you're not getting any audio output from your speakers when you're playing games.  Follow the steps below to resolve the issue:
    Verify that the volume is set to a level you would normally be able to hear.
    Ensure that there is nothing plugged in to the headset jack or the dock connector.
    If the iPhone is in a protective case, make sure that the speaker port isn't blocked by the case.
    Make sure that the speaker and dock port aren't clogged with debris. If necessary, clean it with a clean, small, dry, soft-bristled brush. Carefully and gently brush away any debris.
    If an audio issue occurs when using a specific application, try testing other applications to see if the issue persists.
    If the iPhone is paired with a Bluetooth headset or car kit:
    Try turning off Bluetooth.
    If you experience difficulties with the Bluetooth feature, follow these troubleshooting steps.
    Restart the iPhone.
    If restarting doesn't fix the issue, ensure that your iPhone is updated to the latest version of iOS.
    If the issue is not resolved, please contact Apple Support.
    iPhone: No sound or distorted sound from speaker
    http://support.apple.com/kb/ts5180
    Take care,
    Alex H.

  • My VGA output using Mini DisplayPort to VGA doesn't work.

    Since I upgraded to Mavericks, my VGA output using Mini DisplayPort to VGA doesn't work. When I was using Mountain Lion, as soon as you plugged in the Mini adaopter into the mini display port, the screen would shrink and format to where it would project via a RGB cable to a projector. No such luck since Mavericks! Also, I had a lot of trouble with the DVD player when I tried to play a DVD and project it via a projector. It all worked seamlessly with Mountain Lion. Can anyone help me?

    I think if you go to System Preferences >> Displays and Option-click on the "Scaled" radio button, it will show you all of the resolutions that you would have had before under Mountain Lion. I just upgraded to Maverick and my resolution preferences (mirrored on a TV using the Mini DisplayPort to VGA adapter, using 1280x768) were completely reset (my display was no longer mirrored, and the resolution on my main iMac screen became 2560x1440). I found my answer here: https://discussions.apple.com/message/23599645#23599645. Hope that helps.

  • Generate XML output using DBMS_XMLGEN.getxmltype and not from rdf

    Hi,
    I have a requirement to display output from a particular table in XL format. Out of all the known possible options, I am planning to use the XML publisher to generate XL output.
    For the data source, instead of using the conventional way of creating XML data using rdf,I am planning to use DBMS_XMLGEN.getxmltype pl/sql procedure to generate the XML output. And from the output, call the template to generate the required Excel output.
    Now, I am using the following code to generate XML output but am not sure how to proceed from here. I need to first print the XML data in the FND Output file after which I was planning to call the 'XML Report Publisher' (XDOREPPB) program and use the current request id to get the excel output but I am not able to find the way to print the XML data in the output file as:
    fnd_file.put_line (fnd_file.output, l_xml_type); - is throwing an error as l_xml_type is an XML data output.
    PROCEDURE xml_main (
    errbuf OUT VARCHAR2
    ,retcode OUT VARCHAR2
    ,p_project_from IN VARCHAR2
    ,p_project_to IN VARCHAR2
    AS
    l_xml_type XMLTYPE;
    BEGIN
    SELECT DBMS_XMLGEN.getxmltype
    ('SELECT fnd_global.conc_request_id
    ,TO_CHAR (segment1)
    ,to_char(start_date,''MM/DD/RRRR'')
    ,to_char(xxmcc_project_details_pkg.current_profit_projection
    (project_id),''999,999,990.90'')
    ,to_char(xxmcc_project_details_pkg.cost_to_date (project_id),''999,999,990.90'')
    ,''1''
    FROM pa_projects_all
    WHERE segment1 BETWEEN NVL (p_project_from, segment1)
    AND NVL (p_project_to, segment1)')
    INTO l_xml_type
    FROM DUAL;
         fnd_file.put_line (fnd_file.output, l_xml_type);
    END xml_main;
    Can anyone point me as to how to publish XML output using a PL/SQL procedure (DBMS_XMLGEN.getxmltype)
    Thanks.

    Pl see if the example included in this presentation helps http://www.oracle.com/technology/products/applications/Events/OOW-2006/EBS/S281401_Sridhar_Bogelli.pdf
    Also, you do not need to explicitly call XDOREPPB in later versions of XML Publisher. If you set up everything correctly (as described in the presentation above and the link below) the Output Post Processor is called automatically after the XML file is generated successfully.
    Another excellent tutorial is at http://www.oracle.com/technology/obe/fusion_middleware/fusion/bi/xmlp_ebiz/index.html
    HTH
    Srini

  • Editable field in alv tree output using cl_gui_alv_tree

    Hi,
    i need Editable field with F4 help in alv tree output using cl_gui_alv_tree.
    regards,
    Naresh

    sadly, this is not possible. An ALV Tree cannot by editable.
    Regards

  • Help, just got my iphone5 today and it is still not letting me text or phone or use the apps is there a maximum time i need to leave it for before it will be ready to use??

    got my iphone5 today and its not letting me text or phone or use the internet on it. is there an amount of time i am meant to leave it until i will be able to use this as a phone!

    What did your carrier say when you contacted them about the problem?

  • Is it possible to display a date as (DD-MON-YYYY) in excel output using excel template in xml publisher

    Is it possible to display a date as (DD-MON-YYYY) in excel output using excel template in xml publisher where date should be displayed as date only not string.

    I've tried to use hierarchy node variables, but it seems like you can't specify a attribute of the hierarchy such as level.  So with the WBS hierarchy, if you create a hierarchy node variable, you specify the WBS value to select (If I understand this correctly).  I wish I could instead specify "give me all the WBS nodes that happen to have the value of the level attribute greater or equal to 3.  If I understand Juergens post, he is saying make security access so that only certain WBS levels can be returned in the query.  I suppose we can try that, but that would then preclude getting the level 1 and 2 in the future if the authorization is global.

  • Report VS Excel output using XML Publisher tool (DBMS_XMLGEN)

    Hi All,
    Currently I am working on report generation in MRP module with Excel output using XML Publisher tool.
    XML tool works based on query.
    I have developed PLSQL block by using DBMS_XMLGEN – database package, to generate XML output of query.
    My question is how we can put generated xml on above PLSQL block into OUT file (APPS).
    Because DBMS_OUTPUT.PUT_LINE( ) has limitation, it allow 255 character string only.
    But I do not know, Is FND_FILE.PUT_LINE (FND_FILE.OUTPUT,’’) allow for large data?
    If it does not allow what will be the other solution in oracle application to resolve above problem.
    Let me know any queries regarding to this problem.
    Thanks and Regards,
    Sai Krishna @cavaya.com

    Hi Prakash,
    Thanks for the reply. We did apply the one-off patch and got rid of the problem of not viewing 'Excel' output using XMLP.
    Now we are looking at a different perspective:
    Basically our client is looking for the following:
    1. Mathematical functions in the resulting XLS (like SUM, AVG etc..) ouput
    2. Use of macros if possible.
    And to do this i am looking out for a sample template that gives me output in excel format I have a TAR with Oracle for this purpose, but the TAR has so far been unsuccessful in providing us with any material in the direction.
    Our client remembers seeing this as a demo at the Oracle Conference this yr at San Fransisco, but does not have a sample to provide us. We are looking for such a sample.
    Thx,
    Nitin

  • Excel output using XML Publisher 5.5

    Hi,
    We are trying to obtain output of a simple customer summary report in 'EXCEL" format. For this purpose we have registered a 'RTF' template using which we get output in PDF/RTF formats. We are trying the 'EXCEL' format for the first time. Each time we run the concurrent request for XMLP, and then click 'View Output' we get a pop saying the following message
    "ORA-1403: no data found". The same report works perfectly fine when i run it using the template builder/viewer tool i have on my desktop. Can some throw light on this issue that we are facing.
    Please note that this is extremely important for us, as we plan to design a 'Gross Margin' report using XMLP in 'EXCEL' format and for this, this needs to work. Any inputs will be helpful.
    It would be great if someone in thr group can share a sample RTF template that generates output in 'Excel ' format.
    Tx,
    Nitin Jain

    Hi Prakash,
    Thanks for the reply. We did apply the one-off patch and got rid of the problem of not viewing 'Excel' output using XMLP.
    Now we are looking at a different perspective:
    Basically our client is looking for the following:
    1. Mathematical functions in the resulting XLS (like SUM, AVG etc..) ouput
    2. Use of macros if possible.
    And to do this i am looking out for a sample template that gives me output in excel format I have a TAR with Oracle for this purpose, but the TAR has so far been unsuccessful in providing us with any material in the direction.
    Our client remembers seeing this as a demo at the Oracle Conference this yr at San Fransisco, but does not have a sample to provide us. We are looking for such a sample.
    Thx,
    Nitin

  • TS4268 I CAN NOT RECEIVE TEXT MESSAGES FROM PEOPLE USING IMESSAGE - I HAVE MY IMESSAGE TURNED OFF BECAUSE I DO NOT WANT TEXTS GOING TO ALL MY ACCOUNTS - HOW DO I RESOLVE THIS PLEASE HELP - MISSING SEVERAL IMPORTANT COMMUNICATIONS...

    I CAN NOT RECEIVE TEXT MESSAGES FROM PEOPLE USING IMESSAGE

    On an iPhone your iMessages will go to your phone number.
    You can select another email to use on iPod or iPad.
    Go to settings
    Messages
    Send and receive
    Check your phone number and uncheck the common Apple ID you share so your messages will not go to other devices.

Maybe you are looking for