Text Coordinates in TextArea

I'm trying to write a custom control that extends a text
area, and provides some IDE-style auto-complete functionality. To
do this, I need to be able to position a pop-up menu just below the
start of the word being edited.
So, I need the x and y coordinates of a specific index in my
TextArea. I sort of hoped that a TextRange object would give it to
me, but it doesn't.
Any suggestions?

The textField property of text objects has a
getCharBoundaries method. This returns a Rectangle object
describing the coordinates of any nth character in the text.
I used this to draw rectangles that cover particular words in
a textArea. By getting the rectangle of the first and last
charcters of the word, I could calculate the needed coordinates
from that. The main statements were of this form:
var myRect1:Rectangle =
myTextArea.textField.getCharBoundaries(n);
where n is the character index.
I'm pretty new to Flex, and don't know yet if there is
another way to achieve this. If there is, I'd love to hear.
Regards

Similar Messages

  • How to set two colored text in one textarea

    hello friends,
    i am busy preparing chat frame which shows messages in textarea, it shows two things, one the name of chatter , the other is the message, i want the two things of different color, you can change the text color of textarea by setForeground(), but what if i want different colored text in same textarea, can anybody help me???

    I don't know if this will help u...try make sense of it :
    DefaultStyledDocument doc = new DefaultStyledDocument();
    JTextPane tp = new JTextPane(doc);
    tp.setFont (new java.awt.Font ("Arial", 1, 12));
    JScrollPane lscroller = new JScrollPane(tp);
    lscroller.setForeground (new java.awt.Color (102, 102, 153));
    lscroller.setPreferredSize (new java.awt.Dimension(496, 273));
    lscroller.setVerticalScrollBarPolicy(
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jPanel2.add ( lscroller );
    prepareAllStyles();
    void prepareAllStyles()
    aset = new SimpleAttributeSet();
    //set bold and red
    StyleConstants.setForeground(aset,Color.black);
    StyleConstants.setBold(aset,true);
    ht.put(BOLDRED,aset);
    aset = new SimpleAttributeSet();
    //set italic and green
    StyleConstants.setForeground(aset,Color.red);
    StyleConstants.setBold(aset,true);
    ht.put(ITALICGREEN,aset);
    AttributeSet current = (AttributeSet)ht.get(BOLDRED);
    doc.insertString(doc.getLength(),displaymessage + "\n",current);
    tp.setCaretPosition( doc.getLength() );

  • How to set text in a TextArea

    I have tried to find ways around this, but i must set text into a panel. but there is no .setText(), like there is for text fields. So how would i set text into a TextArea?
    BTW: what i am trying to do is be able to constatly add things without replacing what has been put up there.
    thank you

    BigDaddyLoveHandles wrote:
    sys5 wrote:
    I have tried to find ways around this, but i must set text into a panel. but there is no .setText(), like there is for text fields. So how would i set text into a TextArea?
    BTW: what i am trying to do is be able to constatly add things without replacing what has been put up there.
    thank youCould it be that you are not aware of the documentation?
    http://java.sun.com/javase/6/docs/api/
    By the way, JTextArea does have a setText method, but it replaces the current text with the given text. It sounds like you want to use ---- but wait, it's better if you find that out yourself. Big hint: it's the first method listed on JTextArea's API page.
    edit: too late!If he wasn't aware of the documentation, he probably would have tried using setText(), and found that it worked. That he thought it didn't exist suggests that he looked at the API but only looked in the method summary area, and not below at the "methods inherited from..." sections.
    (sorry to ruin your surprise)

  • How to Align Text in the TextArea

    How to Align text in the TextArea. My purpose is that I want to post the records after retrieving from database. All the records in each fields should keep aligned like Oracle WorkSheet.
    I want this way
    Code Name Place City
    a01 nilopher swiss street japan
    a02 rozina lovely street aus
    a03 benazir king's camp pitsburg
    and the out put should not look like this :-
    Code Name Place City
    a01 nilopher swiss street japan
    a02 rozina lovely street aus
    a03 benazir king's camp pitsburg
    here place and city records are getting disturbed accordingly the length of name.

    Well, first off (if it's not default, that is) you must set a monospaced font on the TextArea, unless you want to count pixelwidth of each and every string and then do an estimate on how many fill blanks you want...
    If you have the each string as a line, you use a StringTokenizer on it, extract each token, put all the tokens for that line into an array of strings.
    When every line is done, you compare the length of the nth String of each array and save the highest numbers.
    Then you reassemble each line from the arrays and pad in spaces where the tokens are too short.
    HTH,
    Fredrik

  • Align text in a textarea

    Greetings,
    Could anyone point me out in how to align a text in a textarea?, as in left/right/center ?
    Thank you

    An easy way to do it is to use a JEditorPane... here's an example class:
    package com.clearlyhazy;
    import javax.swing.*;
    import java.awt.*;
    public class AlignableTextPane extends JEditorPane {
         private static String LEFT = "\"LEFT\"";
         private static String CENTER = "\"CENTER\"";
         private static String RIGHT = "\"RIGHT\"";
         private String alignString = LEFT;
         private String realText;
         public AlignableTextPane() {
              super("text/html", "");
         public AlignableTextPane(String align) {
              super("text/html", "");
              setAlignment(align);
         public void setAlignment(String align) {
              if (align.equals(AlignableTextPane.LEFT) || align.equals(AlignableTextPane.CENTER) || align.equals(AlignableTextPane.RIGHT)) {
                   alignString = align;
         public String getText() {
              return realText;
         public void setText(String t) {
              realText = t;
              super.setText("<P ALIGN=" + alignString + ">" + realText + "</P>");
         public void setText(String t, String alignment) {
              alignString = alignment;
              setText(t);
         public static void main(String[] args) {
              JFrame tester = new JFrame("Alignment Test");
              JPanel mainPanel = new JPanel();
              mainPanel.setLayout(new GridLayout(1, 0));
              AlignableTextPane leftPane = new AlignableTextPane(AlignableTextPane.LEFT);
              leftPane.setText("This text is left-aligned.");
              mainPanel.add(leftPane);
              AlignableTextPane centerPane = new AlignableTextPane(AlignableTextPane.CENTER);
              centerPane.setText("This text is center-aligned.");
              mainPanel.add(centerPane);
              AlignableTextPane rightPane = new AlignableTextPane(AlignableTextPane.RIGHT);
              rightPane.setText("This text is right-aligned.");
              mainPanel.add(rightPane);
              tester.setContentPane(mainPanel);
              tester.setSize(400, 400);
              tester.setLocationRelativeTo(null);
              tester.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              tester.setVisible(true);
    }

  • How do I delete text from a textArea?

    How do I delete text from a textArea? I basically want the opposite of append(String)... I want something that removes a line from my TextArea. Anyone know?>

    If you want to remove only a specific part of the text, you have to get the String, take the parts before and after the removed part, append them back together and use setText to replace it in the textArea.

  • How do I format text within a TextArea

    Hello,
    I would like to create a simple text editor that performs
    syntax highlighting. In order to do so, I would need the ability to
    set the style of individual pieces of text within a TextArea. Is
    this possible? Do I need to subclass the TextArea (or perhaps the
    Text control) to do this? Any pointers in the right direction would
    be appreciated. Thanks!

    The issues around formatting text in the Flash Player are
    numerous. There are several experts who have weighed in on this,
    including .
    Axel
    Jensen who has made available a modification of the
    RichTextEditor component. Additionally,
    Jesse Warden has several older
    articles in his blog on this issue. Finally, there is a
    commercially available Flash/Flex text editor developed by Igor
    (last name unknown to me), and found at:
    http://www.flashtexteditor.com/.
    Overall, the issue of accurately formatting text in
    Flash/Flex has been an exercise in frustration, especially when
    trying to implement htmlText and CSS. I am absolutely amazed that
    Adobe's documentation for this very important aspect of web
    development is either unavailable or deeply flawed, and on top of
    that: How is the Acrobat Connect Buzzword application able to do so
    much with text formatting, clearly within a Flex Framework, and yet
    no concrete documentation of the techniques are available

  • How to get the text of the textArea ?

    Hi, expert
    i have created a new component com1,
    then i created a table view name 'result'.
    then i add a textarea by modifying the result.htm
    textArea id     = "TAMSG"
                     text   = "test......"
    then i add a button in the result.htm
    the method of the button is  'EH_ONSENDMSG'
    then i input some text into the textArea on the page.
    now, how can i get the text of the textArea in the method 'EH_ONSENDMSG' ?
    thanks.
    oliver.

    Hi,
    problem was solved.
    i put the text into a value node.
    <thtmlb:textArea id     = "TAMSG"
                     text   = "//TEXT/TEXT2"
                     encode = "TRUE"
                     width  = "100%" />
    method EH_ONSENDMSG.
      DATA lr_col_wrap      TYPE REF TO   cl_bsp_wd_collection_wrapper.
      DATA lr_query_values  TYPE REF TO   if_bol_bo_property_access.
      DATA lv_str_msg TYPE string.
      lr_col_wrap = me->typed_context->text->get_collection_wrapper( ).
      lr_query_values ?= lr_col_wrap->get_current( ).
      lv_str_msg = lr_query_values->get_property_as_string( iv_attr_name = 'TEXT2' ).
    endmethod.
    regards.
    oliver.

  • Can I display formated text on a TextArea

    I am developing a chat applet. I want to display texts from chatters in a TextArea with specific colour and font. But TextArea only contain a method AppendText(String) where displaying plain text is only possible. Please anyone help me to display formatted text in a TextArea(or any relavent component).
    Thank you very much.

    You will probably want to look at JEditorPane instead.

  • How can i display HTML text in a TextArea

    Hello All,
    We are developing a chat application using Java Swing and RMI with MySQL as backend.
    We have two options.The users can chat thro both browser and application(Swing GUI).
    Now when a user who chats thro a browser sends a message,the chat contents are stored in HTML format in the database (like <BR><font>R u There?</Font></BR>).When the other user happens to chat thro the application,the chat contents send by the other user has to appear in the HTML format in the TextArea of the application.So obviously the textarea shud understand the HTML and display it accordingly.
    How can i do this?Kindly give me an example with some code samples if i have to use EditorPane etc 'coz i haven't got any experience using EditorPanes.
    Thanks in advance
    Regards
    Vijayakannan

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
        public Test() {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container content = getContentPane();
         JEditorPane jep = new JEditorPane("text/html",
                  "Joe: <font color=red>R u <b>There</b>?</Font><BR>"+
                  "Mary: <font color=green>Keep ur shorts on...</Font>");
         content.add(new JScrollPane(jep), BorderLayout.CENTER);
         setSize(200,200);
         show();
        public static void main(String[] args) { new Test(); }
    }

  • A few questions about using an XML file to add text into a TextArea component set as html

    I'm using AS2 in Flash CS3.
    I have a TextArea component in the stage that's loading its text from an XML and I've been able to use the ul and li tags to create lists. However, when I try to include a nested list it just inserts a line break between the nested list and the main list rather than indent it further. Is there a solution for this issue?
    Failing that, how would I be able to add non-breaking spaces into the XML so they will render inside the TextArea component? I've tried   and &#160; without success. I scoured the net for some help with this and found some information about modifying the font embedding xml file with a new entry for the non-breaking space and that didn't work either, so that leaves me somewhat stumped.

    flash doesn't handle nested lists (as you now know).  you can work-around that limitation using css and creating your own indent styles.  css have a marginLeft property you can use.

  • IN OBIEE How to change Writeback input text field into textarea?

    HI,
    I've got writeback working, OBIEE 10.1.3.3, but I want a 255 character in that writeback text field with word wrapping. because we Can't see to get input
    type text to wrap, is it possible to change input type="text" to input type="textarea" for a writeback column?
    I tried to included Html with javascript code in Writeback column properties under CSS custom option.it's also not working
    HTML code:
    <html>
    <head>
    <SCRIPT LANGUAGE="JAVASCRIPT">
    function expandTextArea(textarealabel,e)
    if((textarealabel.textLength %45==0)&(textarealabel.textLength>1))
    if(e.which==8)textarealabel.rows=textarealabel.rows-1;elsetextarealabel.rows=textarealabel.rows+1;
    </SCRIPT>
    </head>
    <body>
    <FORM NAME="Workbook2" ACTION=" " METHOD="">
    <TEXTAREA ID ="Text1" COLS="20" ROWS="2" style="overflow:visible" ONKEYDOWN="expandTextArea this,event);">
    </TEXTAREA>
    </FORM>
    </body>
    <f/html>
    If you have any idea share with me ASAP.
    Edited by: devarasu on Feb 23, 2011 6:57 PM

    Hi thanks for your quick response,
    1) i have cheked you link there is no word Wrapping output, I want to view my writeback filed morethan one line ,is there any way to set instead Horizondal and vertical bar in that writeback filed. like Auto extending TestArea (it have Scrolling bar).
    2) Onemore thing also required,once i gave maximum length of WriteBack field 255 characters. but is not controlling it's allowing morethan 255 characters.kindly tell me how to control the lenth of the writeback field .
    Note: I am using SQL server DB,in DB and BI Answres writeback column properties i given 255 characters only but it's allowing morethan 255 characters.
    once again thanks to you.kindly help me on this ASAP.
    Thanks and Regards,
    Devarasu.R

  • How to change writeback input text field into textarea writeback field?

    Hi,
    I've got writeback working, OBIEE 10.1.3.3, but I want a 100 character in that writeback text field with word wrapping. because we Can't see to get input type text to wrap, is it possible to change input type="text" to input type="textarea" for a writeback column?
    I tried to included Html with javascript code in Writeback column properties under CSS custom option that is also not working.
    Thanks in Advance.
    Devarasu.R

    It's bug in obiee-writeback,it's resolved
    by using external java-jsp application then it will resolved.

  • Using an ArrayCollection as my text for a TextArea

    I have a text area that receives an ArrayCollection as it's
    text something like this:
    <mx:TextArea borderSides="0" horizontalScrollPolicy="off"
    editable="false" text="{getArrayOfCommonNames(
    _deliverableDetail.SFPRespTeamEdit.getmyStringArray() )}"
    wordWrap="true"/>
    when it get's displayed I see a list of names separated by a
    comma. Is there a flag or a simple way of putting each item on a
    new line? I added a \n to the text in my getArrayOfCommonNames
    function which put them on a new line but I still had the commas.
    Any thoughts?

    Thx, I did ended up changing my function from returning an
    array collection to returning a string and using the
    .toString.replace() method to replace the commas to newline
    char's.

  • How to add box around text in s:TextArea?

    Hi,
    What I want to do is I want a red box to appear around some text in my s:TextArea, which is editable.
    Well, I can add a red box by putting the following after my text area.
      <s:Graphic>
        <s:Rect x="20" y="110" width="20" height="20" >
             <s:stroke>
                  <s:SolidColorStroke color="0xFF8888"/>
             </s:stroke>
        </s:Rect>
      </s:Graphic>
    However the user will edit the text, and the text position will change. Also the user will scroll the text area up and down.
    So the location of the box should move to still be located around the text.
    How can I track the position of the text? Is this a good idea? to track the position of the text and to keep moving the box to keep it on top of the text?
    Thanks, Philip

    Philip,
    How about something like this?
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/halo">
        <s:TextArea id="txtArea"
                horizontalCenter="0" verticalCenter="0">
            <s:content>
                <s:p>The quick brown fox jumps <s:span backgroundColor="0xFF0000" backgroundAlpha="0.8">over</s:span> the lazy dog.</s:p>
            </s:content>
        </s:TextArea>
    </s:Application>
    Peter

Maybe you are looking for