Knowing and Manipulating Blinking Caret Position inside a cell in Datagrid in AS3?

Hi, i've made a datagrid and wish to know position of blinking caret within a edited text cell in datagrid in AS3. I know there are some TextField properties available which allow manipulating/highlighting text based on user input. However, i'm unable to access that textField property in a datagrid... any pointers would be of great help....

var columns:Array = ["Flash", "ActionScript", "Republic of Code"];
     trace(columns);
     //Start printing headers 
     var xPos:Number = 0;
     var tbWidth:Number = 0;
     //leave 2 rows margin at top
     var rowY:Number = _rowHeight * 2;
     for (var i = 0; i < columns.length; i++)
          //define xPos by adding the tbWidth of the last loop
          xPos = xPos + tbWidth;
          var column:DataGridColumn = targetDG.getColumnAt(i);
//get width of this column
          tbWidth = column.width;
          //add textField
          printClip.createTextField("header_" + i , printClip.getNextHighestDepth(), xPos, rowY,tbWidth, _rowHeight);
          var thisTb:TextField = printClip["header_" + i];
          //thisTb.setNewTextFormat(headerFormat);
          thisTb.defaultTextFormat = headerFormat;
          thisTb.border = true;
          thisTb.borderColor = 0xCCCCCC;
          thisTb.background = true;
          thisTb.backgroundColor = 0xD5EAFF;
          thisTb.text = column.headerText;
I got this AS2 code and I tried to convent it into AS3 but I have this error..
1046: Type was not found or was not a compile-time constant: DataGridColumn.
I have bold the line that causes this error. Anyone knows the solution for this error?

Similar Messages

  • JEditorPane: transforming between caret position in html and text/plain

    Hi all,
    I've done quite a bit of searching, and found problems similar to this one, but not this exactly, so I'll try asking it here.
    I have a JEditorPane with HTMLEditorKit, which I'm using for a WYSIWYG text editor. When the user wants to insert something, say an image, I get the caret position and insert a String into the document's underlying text.
    The problem is that if we are the WYSIWYG mode, the caret position isn't the same as the caret position in text/plaain mode.
    So if the underlying text is
    <html>
      <body>
         Some text
      </body>
    </html>the user will just see "Some text". If they place the caret between "Some" and "text", editorPane.getSelectionStart() will return '5'. But I want to insert my text at position '16' in the plain text.
    Is there a simple way to go back and forth between these two positions? Or to have getSelectionStart() to return the index relative to the text/plain mode?
    Thanks!
    Tim

    Very poor that no one answered this one.
    Did you still need the answer?
    I have 'a' answer. But not a complete one.
    In fact I only found this in search for an answer for my problem:
    http://forums.sun.com/thread.jspa?threadID=5409216&tstart=0
    Did you actually just test out what you knew so far to test what happens?
    If you were to use the HTMLEditorKit.insertHTML function, it just wants the visual caret position. So '5' would have been reasonably correct for you.
    I was doing something like this:
                   HTML.Tag tag = null;
                   Pattern p = Pattern.compile("\\s*\\<\\s*(\\w+).*", Pattern.MULTILINE|Pattern.DOTALL);
                   Matcher m = p.matcher(text);
                   if (m.matches())
                        tag = HTML.getTag(m.group(1));
                   kit.insertHTML(doc, offset,// +1
                                  text, 0,// 0
                                  0,// 0
                                  tag);
    Assuming you were inserting a tag, my code there checks what tag it is, and if that is known by the java implementation, assigns that to 'tag', so that the element is correctly inserted.
    If it is not known, we just use 'null'. Which for me wasn't such a great result.
    In fact, nothing really was a great result, as with the default java implementation being buggy (so far as I can see) it inserted to the wrong position and caused all sorts of anomalies.
    Hope you worked it out. And if you did, and have a better result than what I have, maybe you can let me know what you did!
    Sincerely,
    sean

  • How to listen and obtain caret positions of changed text in JTextPane?

    Hi,
    I have a JTextPane that displays text with some styles on particular words in the text. For example, I highlight words with red color if they are in my dictionary file. I use regular expression to find matches, replace them with their corresponded definitions, and call setCharacterAttributes to add styles to the definitions. I store all start and end caret positions of the matched words/definitions in a vector. So, I can redisplay styles of all previous matches.
    The problem is that I'd like to be able to edit the text of some previous matches. So, with those changes all caret positions that I already store in the vector need to be updated.
    How can I obtain caret positions of changed text in JTextPane?
    How can I know that a user is currently changing text in the JTextPane?
    How can I get style of text such as color that is being changed?
    Thank you very much.

    Thank you very much, camickr, for your reply.
    I think that I might not know the right way to handle JTextPane and Document object.
    What I have done are:
    - Add style to JTextPane using, for example,
    Style targetCurrentMatchStyle = this.targetWindowTextPane.addStyle("Red", null);
    StyleConstants.setForeground(targetCurrentMatchStyle, Color.red);//For highlight - Then, I use regular expression (Pattern and Matcher) to find a match in text. For each match, I get start and end position from matcher.start() and matcher.end().
    if(matcher.find(start)){
    String term=matcher.group();
    int start=matcher.start();
    int end = matcher.end();
    //find definition for the matched term.
    String definition=mydictionaryHash.get(term);
    //Store caret positions in lists
    startPositionList.add(start);
    matchedLength=lengthList.add(definition.length());
    //Add changed to text in textpane
    StringBuffer sb=new StringBuffer();
    matcher.appendReplacement(sb, definition);
    matcher.appendTail(sb);
    //Get translated text from StringBuffer after replacement
    String translatedText=sb.toString();
    targetWindoTextPane.setText(translatedText);
    //Update start position for next search
    start=start+definition.length();
    //Add style to matched regions below.
    }- From the lists of start positions and matched lengths, I use the following code to add "Red" color to the matched text regions including all previously matched.
    for(int i=0;i<startPositionList.size();i++){
    this.targetWindowTextPane.getStyledDocument().setCharacterAttributes(
    startPositionList.get(i),
    lengthList.get(i),
    this.targetWindowTextPane.getStyle("Red"),
    true);
    }My issue is that I'd like to be able edit previously matched regions and update all positions of the matched regions stored in the lists.

  • I purchased an Ipad mini in Thailand in first week of July. Now the screen of the ipad has lost its brightness and smells like somethings burning inside when switched on. I am in Dubai now and want to know if I can have it exchanged here in Dubai?

    I purchased an Ipad mini in Thailand in first week of July. Now the screen of the ipad has lost its brightness and smells like somethings burning inside when switched on. I am in Dubai now and want to know if I can have it exchanged here in Dubai?

    Contact support and ask them. http://www.apple.com/support/contact/

  • HT3412 I just ordered and received 2 large Hardcover photo books and one arrived with the inside binding messed up. Do you know how this can get corrected?

    Have you tried returning a photo book that has a binding problem? I just ordered 2 large hardcover photobooks and one arrived with the inside binding messed up. Do you know how this can get corrected? They were over $80 and it seems they should not be flawed. I would appreciate any tips. lindajenkins

    Contact Apple Support - link at the bottom of every page of these forums
    LN

  • Getting to know caret position

    when backspace is keyed, is there a way to know whether the caret in a textPane has return to the previous line??
    e.g
    the caret is at the beginning of line 2 of the textpane... by keying backspace,the caret will return to line 1.. is there a way to know that the caret has return to the previous line?

    The following code will tell you the current line number of the caret. So you will need to add some before/after logic to tell if the line number has changed:
    **  Return the current line number at the Caret position.
    public static int getLineAtCaret(JTextComponent component)
         int caretPosition = component.getCaretPosition();
         Element root = component.getDocument().getDefaultRootElement();
         return root.getElementIndex( caretPosition ) + 1;
    }

  • WebView / HTMLEditor - caret position and selected content

    Hey :)
    Is it possible to get the caret position and the selected content in the HTMLEditor / WebView? How?
    Thanks in advance.

    Use JavaScript methods. For example:
    http://stackoverflow.com/questions/9370197/caret-position-cross-browser
    http://stackoverflow.com/questions/6129006/get-the-raw-html-of-selected-content-using-javascript
    Use the Java\JavaScript bridge if you want the result in Java:
    http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm

  • Is caret positioning in right-to-left oriented jtextpane corruptable?

    Dear all -
    Below is a serious problem. I hope I can get help from you experts out there; otherwise, I think it is a bug that should be reported to the JDK developers.
    I am writing an editor using my own keyboard layout to type in Arabic. To do so, I use jTextPane, and my own implementation of DocumentFilter (where I map English keys to Arabic letters). I start by i) setting the component orientation of jTextPane to be from RIGHT_TO_LEFT, and ii) attaching a caretListener to trace the caret's position.
    The problem (I think it is a bug just like what is recorded here: http://bugs.adobe.com/jira/browse/SDK-16315):
    Initially as I type text in Arabic, there is one-to-one correspondence between where I point my mouse and where the caret displays, basically, the same place. However, a problem occurs (and can always be re-produced) when I type a word towards the end of the line, follow it by a space character, and that space character causes the word to descend to the next line as a result of a wrap-around. Now, as I point my mouse to that first line again, the location where I click the mouse and the location where the caret flashes are no longer coincident! Also, the caret progression counter is reversed! That is, if there are 5 characters on Line 1, then whereas initially the caret starts from Position 0 on the right-hand side and increases as more text is added from right to left, it is now reversed where the the caret now increases from left to right for the first line, but correctly increases from right to left in the second line! yes funny stuff and very hard to describe to.
    So, here is an example. I wrote the code below (JDK1.6_u10, on Netbeans 6.5 RC2) to make it easy to reproduce the problem. In the example, I have replaced the keys A, S, D, F and G with their Arabic corresponding letters alif, seen, daal, faa and jeem. Now, type these letters inside the double quotes (without the double quotes) including the two spaces please and watch out for the output: "asdfg asdfg ". Up until you type the last g and before you type space, all is perfect, and you should notice that the caret position correctly moves from 0 upwards in the printlines I provided. When you type that last space, the second word descends as a result of the wrap-around, and hell breaks loose! Notice that whereas the mouse and caret position are coincident on the second line, there is no way to fine-control the mouse position on the first line any more. Further, whereas adding text on the second line is intuitive (i.e., you can insert more text wherever you point your mouse, which is also where the caret would show up), for the first line, if you point the mouse any place over the written string, the caret displays in a different place, the any added text is added in the wrong place! All this because the caret counter is now reversed, which should never occur. Any ideas or fixes?
    Thank you very much for reading.
    Mohsen
    package workshop.onframes;
    import java.awt.ComponentOrientation;
    import java.awt.Rectangle;
    import javax.swing.event.CaretEvent;
    import javax.swing.event.CaretListener;
    import javax.swing.text.BadLocationException;
    public class NewJFrame1 extends javax.swing.JFrame {
    public NewJFrame1() {
    initComponents();
    jTextPane1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    CaretListener caretListener = new CaretListener() {
    public void caretUpdate(CaretEvent e) {
    int dot = e.getDot();
    int mark = e.getMark();
    if (dot == mark) {
    try {
    Rectangle cc = jTextPane1.modelToView(dot);
    System.out.println("Caret text position: " + dot +
    ", view location (x, y): (" + cc.x + ", " + cc.y + ")");
    } catch (BadLocationException ble) {
    System.err.println("CTP: " + dot);
    } else if (dot < mark) {
    System.out.println("Selection from " + dot + " to " + mark);
    } else {
    System.out.println("Selection from " + mark + " to " + dot);
    jTextPane1.addCaretListener(caretListener);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jScrollPane3 = new javax.swing.JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextPane1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
    jTextPane1.setAutoscrolls(false);
    jTextPane1.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyTyped(java.awt.event.KeyEvent evt) {
    jTextPane1KeyTyped(evt);
    jScrollPane3.setViewportView(jTextPane1);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
    .addContainerGap())
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    private void jTextPane1KeyTyped(java.awt.event.KeyEvent evt) {
    if (evt.getKeyChar() == 'a') {
    evt.setKeyChar('\u0627');
    } else if (evt.getKeyChar() == 's') {
    evt.setKeyChar('\u0633');
    } else if (evt.getKeyChar() == 'd') {
    evt.setKeyChar('\u062f');
    } else if (evt.getKeyChar() == 'f') {
    evt.setKeyChar('\u0641');
    } else if (evt.getKeyChar() == 'g') {
    evt.setKeyChar('\u062c');
    public
    static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame1().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration
    }

    Hi Mohsen,
    I looked at it and indeed, I see what you describe. Sorry, but I can't shed any light. I tried to figure out what software component, or combination of components, is the cause of the problem. I see several candidates:
    1) The JTextPane
    2) The Document
    3) RTL support
    4) BIDI support
    5) Interpretation (by any other software component) of the left and right arrow key
    6) The font
    To clarify number 6: I know virtually nothing of Arabic language (apart from it being written from right to left). I remember however that the actual representation of a letter is dependent of its position between other letters: front, middle and end. What I see to my astonishment is that it seems that the rendering is also aware of this phenomenon. When you insert an A between the S and D of ASDFG, the shape of the S changes. Quite magic.
    I tried to add a second textpane with the same Document, but a different size, to see what would happen with number one if one types text in number two and vice versa.
    In my first attempt, the font that you set on textpane one was gone after I set its document to number two. For me that is very strange. The font was set to the textpane, not to the document. The separation betweem Model and View seems not very clear in this case. So I now also set that font on the second textpane.
    I will post the changed code so that you may experiment some more and hopefully will find the problem.
    You might be interested in a thread on java dot net forums that discusses a memory leak for RTL [http://forums.java.net/jive/message.jspa?messageID=300344#300344]
    Piet
    import java.awt.ComponentOrientation;
    import java.awt.EventQueue;
    import java.awt.Font;
    import java.awt.Rectangle;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.GroupLayout;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.WindowConstants;
    import javax.swing.event.CaretEvent;
    import javax.swing.event.CaretListener;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.Document;
    public class NewJFrame1 extends JFrame {
        private static final long serialVersionUID = 1L;
        public NewJFrame1() {
         initComponents();
         // jTextPane1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
         this.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
         CaretListener caretListener = new CaretListener() {
             public void caretUpdate(CaretEvent e) {
              int dot = e.getDot();
              int mark = e.getMark();
              if (dot == mark) {
                  try {
                   Rectangle cc = jTextPane1.modelToView(dot);
                   System.out.println("Caret text position: " + dot
                        + ", view location (x, y): (" + cc.x + ", "
                        + cc.y + ")");
                  } catch (BadLocationException ble) {
                   System.err.println("CTP: " + dot);
              } else if (dot < mark) {
                  System.out.println("Selection from " + dot + " to " + mark);
              } else {
                  System.out.println("Selection from " + mark + " to " + dot);
         jTextPane1.addCaretListener(caretListener);
        private KeyAdapter toArabic = new KeyAdapter() {
         public void keyTyped(KeyEvent evt) {
             jTextPane1KeyTyped(evt);
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
        // @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
         jScrollPane3 = new JScrollPane();
         jTextPane1 = new JTextPane();
         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
         jTextPane1.setFont(new Font("Tahoma", 0, 24)); // NOI18N
         jTextPane1.setAutoscrolls(false);
         jTextPane1.addKeyListener(toArabic);
         jScrollPane3.setViewportView(jTextPane1);
         GroupLayout layout = new GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(layout.createParallelGroup(
              GroupLayout.Alignment.LEADING).addGroup(
              layout.createSequentialGroup().addContainerGap().addComponent(
                   jScrollPane3, GroupLayout.DEFAULT_SIZE, 159,
                   Short.MAX_VALUE).addContainerGap()));
         layout.setVerticalGroup(layout.createParallelGroup(
              GroupLayout.Alignment.LEADING).addGroup(
              layout.createSequentialGroup().addContainerGap().addComponent(
                   jScrollPane3, GroupLayout.PREFERRED_SIZE, 85,
                   GroupLayout.PREFERRED_SIZE).addContainerGap(
                   GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
         pack();
        }// </editor-fold>
        private void jTextPane1KeyTyped(KeyEvent evt) {
         if (evt.getKeyChar() == 'a') {
             evt.setKeyChar('\u0627');
         } else if (evt.getKeyChar() == 's') {
             evt.setKeyChar('\u0633');
         } else if (evt.getKeyChar() == 'd') {
             evt.setKeyChar('\u062f');
         } else if (evt.getKeyChar() == 'f') {
             evt.setKeyChar('\u0641');
         } else if (evt.getKeyChar() == 'g') {
             evt.setKeyChar('\u062c');
        public static void main(String args[]) {
         EventQueue.invokeLater(new Runnable() {
             public void run() {
              final NewJFrame1 frameOne = new NewJFrame1();
              frameOne.setLocationRelativeTo(null);
              frameOne.setVisible(true);
              EventQueue.invokeLater(new Runnable() {
                  public void run() {
                   Document doc = frameOne.jTextPane1.getDocument();
                   JTextPane textPane2 = new JTextPane();
                   textPane2.setFont(new Font("Tahoma", 0, 24)); // NOI18N
                   textPane2.setAutoscrolls(false);
                   textPane2.setDocument(doc);
                   textPane2.addKeyListener(frameOne.toArabic);
                   JFrame frameTwo = new JFrame();
                   frameTwo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   frameTwo.add(new JScrollPane(textPane2));
                   frameTwo.setSize(400, 300);
                   frameTwo.setLocationByPlatform(true);
                   frameTwo.setVisible(true);
                   frameTwo
                        .applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        // Variables declaration - do not modify
        private JScrollPane jScrollPane3;
        private JTextPane jTextPane1;
        // End of variables declaration
    }

  • Javascript: set or get caret position in textarea -not in IE?

    Hi all
    another javascript question...
    I'm using a javascript function that gets the caret position
    (the cursor position) in the textarea,
    and stores it when the textarea gets out of focus, so that
    text can be inserted by clicking on a
    button, where the caret was previously in the textarea.
    I suppose many cms or html editors do that successfully
    somehow.
    But my function works in all browsers BUT IE.
    I remember giving up with the same problem years ago after I
    found documentation on how impossible
    or unreliable it was to make this work in IE.
    But I thought times had changed, and IE7 would improve on
    that matter.
    Apparently not?
    I found many that claim to work in all browsers, but the one
    I choose to use obviously does not...
    So do you guys know a script that does that and WORKS with
    IE?
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    An Ingenious WebSite Builder:
    http://sitelander.com

    I'll link you something tonight - I wrote it like five years
    ago when I was in grade eleven. It's ugly code (as far as I can
    remember), but it has really advanced features and is REALLY easy
    to adapt to most situations.

  • JTextPane- Getting Caret Position

    Hi All - Can somebody please let me know if there is a way to know the co-ordinates of the end of a line which was read at a particular location in a JTextPane. In other words if I have jTextPane with text
    "Welcome to the bizarre world of JTextPane."Now if I read some text say "SOMETHING" at the end of the word of, I would like the line to be
    Welcome to the bizarre world of SOMETHING of JTextPane with the caret position at the end of SOMETHING. Can somebody shed some light on it. Here's the basic code that I have written down.
    the param str would be some html tag String. I can post more code if confusing.
    private static void readToEditor(JTextPane textPane, String str) throws Exception
    HTMLEditorKit kit = (HTMLEditorKit) textPane.getEditorKitForContentType("text/html");
    ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
    Reader reader = new BufferedReader(new InputStreamReader(stream))
    HTMLDocument doc = (HTMLDocument) textPane.getDocument();
    int pos = textPane.getCaretPosition();
    kit.read(reader, doc, textPane.getCaretPosition());
    reader.close();
    // The Swing Bug handled here which puts in a "\n" unnecessarily before reading HTML Tags.
    String theBug = doc.getText(pos, 1);
    if (theBug.equals("\n"))
    doc.remove(pos, 1);
    }Thanks so much for looking.

    Do you mean how to take the int that is returned from
    editorPane.getCaretPosition();
    and figure out what HTML is at that position?
    HTMLEditorKit (javax.swing.text.html) may help. Also check out class HTMLDocument and its method getReader(int pos).
    Sorry, I haven't actually done this, so I am just throwing out ideas.
    Barb

  • JTextPane caret position

    hi all.....i just dont get it why the blink-pointer (which define your text position when you type) of my JTextPane always get to the end. by default it gets to the end after u type something. But if i want to edit the middle part of my text, i need to press "<-" to backward the blink-pointer position....but it always get to the end of the text.. it seems to be hardly moved from the end position.
    Any suggestion of how do i set it to be normal?

    I don't understand the question. The carets stay where you are typing in the text pane. It doesn't move to the end unless you move it there.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",
    see http://homepage1.nifty.com/algafield/sscce.html,
    that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the "Code Formatting Tags",
    see http://forum.java.sun.com/help.jspa?sec=formatting,
    so the posted code retains its original formatting.

  • JcomboBox caret position

    I want to create a jcombobox that accepts only dates... But I have no idea how to capture the caret position.....
    There doesn't seem to be another default method to know where the caret position.
    Any help?
    Thanks,
    V

    Well first of all to even have a caret in your combo box you need to make sure you have it set as editable.
    This is a good tutorial to show you how...
    http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#editable
    Using the example ComboBoxDemo2.java from that tutorial I was able to add a few lines of code to get the caret position. Since the JComboBox class does not implement the getCaretPosition() you can use the method getEditor() to return the ComboBoxEditor. Then use the ComboBoxEditor's method getEditorComponent and cast it to a JTextField. Now you can use the JTextField's method getCaretPosition() to return the caret position.
    Does that make sense? I was able to get it to work that way.
    Good luck,
    .kim

  • Find caret position of search text in jEditorPane

    Hi All,
    I am looking for a way to find the Caret position in a jeditor pane for the search text that i supply. The Jeditor pain is setup for text/html and when i find the index of my search text "ANCHOR_d" in the jeditor pane is 27000 something but the caret position is 7495 how do you find the caret position of the search text ??
    Any help is appriciated.
    I am also looking into getting abnchoring to work in the jeditorpane html text but as of yet i have been unsuccessful.
    Kind Regards,
    Wurns

    Search the underlying document, not the editor pane. Play around with this example, which I threw together the other day for a somewhat similar problem with JTextPane involving newlines, and modified for your need.
    Note: Please do not program by exception.import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import javax.swing.JButton;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.text.Document;
    public class SearchEditorPane {
       JFrame frame = new JFrame ("Search JTextPane Test");
       String html = "<HTML><BODY><P>This is <B>some</B>" +
                    " <I>formatted</I>" +
                    " <FONT color=#ff0000>colored</FONT>" +
                    " html.</P>" +
                    "<P>This is a <FONT face=Comic Sans MS>" +
                    "comic <br>\n<br>\nsans ms</FONT> section</P><div>" +
                    "And this is a new division</div>" +
                    "</BODY></HTML>";
       JEditorPane editorPane = new JEditorPane ("text/html", html);
       JPanel panel = new JPanel ();
       JTextField textField = new JTextField (10);
       JButton button = new JButton ("Find");
       Document doc = editorPane.getDocument ();
       void makeUI () {
          editorPane.setText ("<HTML><BODY><P>This is <B>some</B>" +
                " <I>formatted</I>" +
                " <FONT color=#ff0000>colored</FONT>" +
                " html.</P>" +
                "<P>This is a <FONT face=Comic Sans MS>" +
                "comic <br>\n<br>\nsans ms</FONT> section</P><div>" +
                "And this is a new division</div>" +
                "</BODY></HTML>");
          button.addActionListener (new ActionListener () {
             public void actionPerformed (ActionEvent e) {
                // Programming by exception is BAD, don't copy this style
                // This is just to illustrate the solution to the problem at hand
                // (Sorry, uncle-alice, haven't reworked it yet)
                try {
                   Matcher matcher = Pattern.compile (textField.getText ())
                   .matcher (doc.getText (0, doc.getLength ()));
                   matcher.find ();
                   editorPane.setCaretPosition (matcher.start ());
                   editorPane.moveCaretPosition (matcher.end ());
                   editorPane.requestFocus ();
                } catch (Exception ex) {
                   JOptionPane.showMessageDialog (frame, "Not Found!\n" + ex.toString ());
                   //ex.printStackTrace();
          panel.add (textField);
          panel.add (button);
          panel.setPreferredSize (new Dimension (300, 40));
          frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          frame.setSize (300, 300);
          frame.add (editorPane, BorderLayout.CENTER);
          frame.add (panel, BorderLayout.SOUTH);
          frame.setLocationRelativeTo (null);
          frame.setVisible (true);
       public static void main (String[] args) {
          SwingUtilities.invokeLater (new Runnable () {
             public void run () {
                new SearchEditorPane ().makeUI ();
    }db

  • I hired a commercial artist to create a color image for the cover of a self published book. I want a black and white image for the inside. The commercial artist has not responded to this request. How do I determine the format of the color image, I'm guess

    I hired a commercial artist to create a color image for the cover of a self published book. I want a black and white image for the inside. The commercial artist has not responded to this request. How do I determine the format of the color image, I'm guessing it's Illustrator's formatting but I don't know. How can I find out if Illustrator will open the file and allow alterations? The image opens only in Apple's Pages software?

    rons,
    It seems that all you have is a raster image, presumable PNG24 or JPEG, in RGB.
    It may have been created as raster artwork in Photoshop, or it may have been created as vector artwork with the help of Illy, or as a mixture of vector and raster artwork in either application, or both combined.
    If you just need to have a raster representation in black and white based on the current colour image, you may try this, in a new RGB document (View>Smart Guides are your friends):
    1) File>Place the image (you may tick Link or untick and have it embedded);
    2) Create a rectangle with black fill (R = G = B = 0), at least as large as the image, and place it behind the image (you may ClickDrag with the Rectangle Tool between opposite corners, then Ctrl/Cmd+X+B);
    3) Select all and in the Transparnecy palette flyout click Make Opacity Mask with both Clip and Invert Mask ticked.

  • Setting Caret Position

    Dears,
    How do I set the Caret position to a required position in the SpinnerNumberModel? Do I need to use setDot() and NavigationFilter? The position should be set as soon as Spinner is constructed.
    Please help.
    Thanks,
    Raj

    Hi,
    I didn't get it work too, but this workaround seems to work.
    Cheers
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.scene.Scene;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class CaretPositioner extends Application {
         public static void main(String[] args) {
              Application.launch((java.lang.String[]) null);
         @Override
         public void start(Stage primaryStage) {
              BorderPane root = new BorderPane();
              final TextField tf = new TextField();
              tf.textProperty().addListener(new ChangeListener<String>() {
                   @Override
                   public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
                        System.out.println(tf.getCaretPosition());
                        Platform.runLater(new Runnable() {
                             @Override
                             public void run() {
                                  tf.positionCaret(0);
              root.setCenter(tf);
              Scene scene = new Scene(root);
              primaryStage.setScene(scene);
              primaryStage.show();
    }

Maybe you are looking for

  • Two user accounts - transfer e-mail from one to the other.

    Hi, I set up a private account and would like to move mail from my main account into the in/out boxes of my private account - some files but not all. How do I transfer between them?

  • Checks in Case statement

    Need help in checking one status among all other columns Emp BonusStatus A Remove A Accepted Select  Emp, Case when BonusStatus is 'Accepted'  then ' issue bonus' ELSE ' No bonus' End as bonus_res From #temp  o/p : EMp    Bonus_Res A No bonus A Issue

  • Tabs and iframe

    I am not sure if this posted the first time or not, so I am reposting it. Thank you in advance for your understanding. (APEX) I have two applications. The first application has tabs. Each page in application 1 has an html region with <iframe> referen

  • Being Asked for Database Logon Twice

    I am using VS2010 and have created a webpage to display a report.  I load up a report using a stored procedure into the Viewer.  When I click to export the report, it wants to open up another window and then asks for the logon information again. Belo

  • Which Logic version is reliable

    Hi all, I am using Logic 8 at the moment with not the newest Power Mac G4 computer and I get the "system overloaded" message. I thought it might be the old computer and was thinking to buy a new one. I went to Apple store today to test the best Mac B