Position of the caret in JEditorPane HTML

Hello world
I need the position of the caret in the HTML source on JEditorPane. I have
The value of getCaretPosition() is not what I wanted. CaretEvent.getDot () gives the same value of getCaretPosition. These methods only gets position on the view.
Help, please! Thank you very much!

It is not possible. HTMLParser creates the structure of the Document (tree of items) of html text, but it has nothing to do with the content.
Position in the html source is not correct because it can hold to support the space between the labels or tab characters or \n tanks that are ignored.

Tags: Java

Similar Questions

  • WebView / HTMLEditor - position of the caret and content selected

    Hey :)

    Is it possible to get the position of the caret and selected content in the HTMLEditor / WebView? How?

    Thanks in advance.

    Use the 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 bridge to Java\JavaScript if you want the result in Java:
    http://docs.Oracle.com/JavaFX/2/WebView/jfxpub-WebView.htm

  • Position of the caret

    Hi all

    Is there an easy way to display the numbers in row and column of the current position of the cursor in a JTextComponent?

    Currently, I get the position of the caret that is an absolute position from the beginning of the component and the loop through the lines until I find the current line. It's ok for the small text, but great text, may not be very effective.

    Thank you

    Discover text utilities [url http://tips4java.wordpress.com/2008/10/26/text-utilities/] of camickr

    DB

  • AF:inputtext change the color of the text on pressure from button and the position of the caret

    Hi all

    Very green, when it comes to ADF so I hope to give you enough information to get assistance.

    I found a 2008 document that created Frank Nimphius that shows how the JavaScript in the ADF and the manipulation of the inline style property.

    It is titled "ADF Code corner 010. How to create a character counter of entry for text fields.

    While my use case is not the same I feel that I could use for my use case logic.

    My use case is that the user wants a text field to replace the blue color when being typed in so that they know what they changed.

    I'm jusing JDeveloper 12.1.2

    That's what I have my input text looks like:

    <af:column sortProperty="#{bindings.ChiefScaleOrderVO.hints.OrderNo.name}" filterable="true"
                                   sortable="true" headerText="#{bindings.ChiefScaleOrderVO.hints.OrderNo.label}" id="c1"
                                   width="11%" inlineStyle="#{recordManager.columnStyle}">
                          <af:inputText value="#{row.bindings.OrderNo.inputValue}"
                                        label="#{bindings.ChiefScaleOrderVO.hints.OrderNo.label}"
                                        columns="#{bindings.ChiefScaleOrderVO.hints.OrderNo.displayWidth}"
                                        maximumLength="#{bindings.ChiefScaleOrderVO.hints.OrderNo.precision}"
                                        shortDesc="#{bindings.ChiefScaleOrderVO.hints.OrderNo.tooltip}" id="it1"
                                        autoSubmit="true" valueChangeListener="#{recordManager.columnTextModified}"
                                        clientComponent="true">
                            <af:clientListener method="keyInput" type="keyPress"/>
                            <f:validator binding="#{row.bindings.OrderNo.validator}"/>
                          </af:inputText>
                        </af:column>
    

    This is what looks like my javascript:

    <af:resource type="javascript">
           function keyInput(evt){
              //document.getElementById(evt.getSource().getClientId() + '::content').style.color = 'blue';
              textfield = evt.getCurrentTarget();
              textfield.setInlineStyleProperty("color","blue");
           }
    </af:resource>
    
    

    If I do an alert (textfield.getInlineStyleProperty("color")); before and after the the setInlineStyleProperty it does not say it gets the value at the blue, but my text color never changes.

    If I do the document.getElementById (evt.getSource () .getClientId () + ': content ""). style.color = "blue"; It works, but I'm doing things the "right way".

    So is there another way to do this now in 12 JDeveloper?

    Also is there anyway to when you click inside an af:inputText that he will not select all of the text and just position the cursor at the end?

    Thank you

    Derek Hansen

    Well, you try to set the wrong property.

    According to your example of "pure" javascript, you must set contentStyle and not inlineStyle.

    Then try something like: textfield.setContentStyle ("color: Blue");

    Dario

  • Insert text at the caret position in TextArea

    How to add text in the text box to the position of the user clicked? Looked everywhere, but couldn't find any way...

    Here's one way:


    <>
    ' xmlns:MX =' http://www.adobe.com/2006/mxml '
    x = "0" y = "0".
    paddingLeft = "0".
    paddingTop = "0".
    paddingBottom = "0".
    paddingRight = '0 '.
    backgroundColor = "#FFFFFF" >

    private void insertText (): void
    {
    var: string text = happyTextArea.text;
    happyTextArea.text = text.substr(0,happyTextArea.selectionEndIndex) + 'happy' + text.substr (happyTextArea.selectionEndIndex);
    }

    ]]>




  • Problem to find the Position of the cursor by using Java Script for an input TextField

    Hello

    I have a problem to find the position of the cursor in a field inputText component.

    The following code of java script to achieve. The same functionality works fine if I run in a simple html page. But when it is used the same javascript inside the jsff does not the position of the cursor.
    var adfComponent = AdfPage.PAGE.findComponentByAbsoluteId("r1:1:it3");
    var adfComponentClientId = adfComponent.getClientId();
    var div = document.getElementById(adfComponentClientId + '::content');
    div.focus();
    var docSelectionRange = document.selection.createRange();
    
    docSelectionRange.moveStart ('character', -div.value.length);
    
    var iCaretPos = docSelectionRange.text.length;
    
    alert("iCaretPos --> "+iCaretPos);  ---> This statement always returning '0'. Instead, i want the cursor position inside the text box.
    Please let me know what I'm missing.

    For your reference, sending the sample page html that works fine with the same kind of code.
    <html>
     
     <body style="font-family: tahoma; font-size: 8pt;">
     
      <script language="JavaScript">
     
       /*
       **  Returns the caret (cursor) position of the specified text field.
       **  Return value range is 0-oField.length.
       */
       function doGetCaretPosition (oField) {
     
         var iCaretPos = 0;
              alert(oField);
         if (document.selection) { 
     
           // Set focus on the element
           oField.focus ();
     
           // To get cursor position, get empty selection range
           var oSel = document.selection.createRange ();
     
           // Move selection start to 0 position
           oSel.moveStart ('character', -oField.value.length);
     
           // The caret position is selection length
           iCaretPos = oSel.text.length;
         }
     
         // Firefox support
         else if (oField.selectionStart || oField.selectionStart == '0')
           iCaretPos = oField.selectionStart;
     
         // Return results
         return (iCaretPos);
       } 
      
     
     
      </script>
     
      <form name="blah">
     
       Text Field: <input type="text" name="nameEdit" value="">
       <input type="button" value="Get Caret" onClick="document.getElementById('where').value=doGetCaretPosition (document.forms[0].elements[0]);">
    <input id="where">
      
     
      </form>
     
     </body>
     
    </html>
    Thank you and best regards,
    Kiran kristelle

    Published by: Kiran kristelle on February 6, 2012 12:00

    ... had the chance to look at the source code of the sample. ADF Faces renders text as HTMLTextArea fields when the value of the rows property. The JavaScript code used in the example of client works differently for FF and IE if the input is a text box. This could be a problem in IE or just used JavaScript code. The rows back to a single line (remove) property makes the text as HTML input feldworking with the JavaScript for IE and FF.

    Frank

  • Web design resource who reads the entered text in html file

    Hello

    I have a Web page that displays the contents of a JSON array published by a Web Service in LabVIEW currently. The web page also accepts input from the user. See attached extract entries. The HTML code associated with entries is fixed also. Currently, when the page is refereshed the values entered in the text fields disappear. So, I want to be able to store values entered in the space of memory of the web service in some way. Perhaps through the use of NPSV? If so, the page is refreshed, the input fields can then be re-populated rereading the information stored inside the NPSV.

    I started the position down the path of creating a resourc web which would read as follows in these values, but I don't know how to do this job.

    Someone you will suggest a way that this could work? Perhaps refer to examples?

    I'm using LabVIEW 2015 SP1 on a cRIO-9068.

    See you soon

    Conrad

    Hello

    Have you seen the following:

    https://decibel.NI.com/content/docs/doc-41659

  • How to add text to the position of the cursor in HTMLEditor in JavaFX

    I know how to add new button to HTMLEditor and I want all of my action button to paste text at the current position of the cursor.


    //HTMLEditor html;
    //String IMAGE_URL = "http://...";
    Node node = html.lookup(".top-toolbar");
    if (node instanceof ToolBar) {
      
    ToolBar bar = (ToolBar) node;
      
    ImageView graphic = new ImageView(new Image(IMAGE_URL, 32, 32, true, true));
      
    Button myButton = new Button("", graphic);
      bar
    .getItems().add(myButton);
      myButton
    .setOnAction(new EventHandler<ActionEvent>() {
      
    @Override
      
    public void handle(ActionEvent arg0) {
      
    //needs code
      
    }
      
    });
    }

    Use the webkit API, so this isn't something you want to use in production since there is no guarantee that JavaFX will use webkit in the future. Really, the HTMLEditor should have an API editor that makes all of this transparent.

    You will need to import javafx.scene.web.WebView, com.sun.javafx.webkit.Accessor, and com.sun.webkit.WebPage;

                myButton.setOnAction(new EventHandler() {
                    @Override
                    public void handle(ActionEvent arg0) {
                        WebView webView = (WebView)htmlEditor.lookup("WebView");
                        WebPage webPage = Accessor.getPageFor(webView.getEngine());
                        webPage.executeCommand("insertText", " World Cup Soccer ");
                    }
                });
    
  • Can not get the position of the - invalid parent node

    My team has just started to use the Muse of creating HTML DPS Article. In order to maintain interactivity familiar or similar to what our customers have been used to with articles based on InDesign, we use Widgets of Muse-topics in our files.

    I met a problem that I'm not sure is associated - widget. Trying to use the widget of Muse-theme pushy shutters, I received this error when you are trying to preview:

    "Can't get the position of note - invalid parent."

    Screen Shot 2016-02-10 at 10.17.19 PM.png

    Initially, we had 2 cases of the active widget - for 2 different breakpoints (using the latest version with sensitive provision). I removed one instance of the widget, but still have the error. I tried exchanging and removed the other instance - still have the error.  I went up to remove TWO instances of the widget, and the file STILL generated the error.  I thought that since the upstart components is no longer present, maybe just having Graphic Styles covered in the Parent/child agreement attempts to call something (I obviously don't know Muse very well yet...). So, I removed all instances of graphic themes as well, and again, Muse has generated the error even on preview.

    I'm really at a loss... What generates this kind of thing. My file is corrupt? What can I do to fix this?

    Any suggestions will be greatly appreciated.

    Thank you

    Tommy

    I think we have tracked the issue down for, quite simply, a source image missing who was left on the disk hard of the original designer, rather than on the server where the site is hosted. UGH!

  • FancyBox - How can I change the position of the title to the INSIDE of the box?

    I know that this may not be the place to ask this question involves the jQuery and Fancybox, but I'm uncomfortable with the Dreamweaver Forum so thought I would ask. Earlier, I started working on this project for an artist and thought that FancyBox would be a good way to present his work. I don't know much about jQuery and Fancybox, but managed to make it work, which is not particularly difficult. That is, how can I change the position of the TITLE by default out of the BOX on the INSIDE of the box. I played with the CSS a bit, ask about these things called aid, tried to put a code of jQuery in the head section, but nothing helped.

    Here is a link to the page (forgive the look, still under development): www.watercolorsplus.com/New/babyFootprints2.html

    There are still a few errors in the tag, as can be seen here [Valid] Markup Validation of http://www.watercolorsplus.com/New/babyFootprints2.html - W3C Markup Validator

    Fix the above errors first in particular the absence of citations which surround the fancybox (x 4) as in

    a class = """"" " fancybox

    When the above errors were fixed, add the part highlighted in the constructor.

    {$(document) .ready (function ()}

    $(".fancybox").fancybox ({}

    aid: {}

    Title: {}

    type: 'inside '.

    },

    overlay: {}

    CSS: {}

    'background': 'rgba (255,255,255,0.5).

    }

    }

    }

    });

    });

  • TextField affecting the caret at the end when losing point on

    Hey everybody,

    I would like to put the caret of a TextField at the end of the text when the textfield loses focus, so that the last part of the name of the file will be shwon and not the first part. I ve tried the following:
    ChangeListener<Boolean> onLooseFocus = new ChangeListener<Boolean>() 
             { 
                  @Override
                  public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) 
                  {
                       if (!newValue.booleanValue()) 
                       {
                            textFieldDateiname.end();     
                                    System.out.println(textFieldDateiname.getCaretPosition()); 
                                    // At this point the caret is at the end and it will show:
                                    //ReadOnlyIntegerProperty [bean: TextField[id=textFieldDateiname, styleClass=text-input text-field], name: caretPosition, value: 76]
                       }
                  }
             };
    This ChangeListener is added to the focusedProperty() of my TextField method
    textFieldDateiname.focusedProperty().addListener(onLooseFocus);
    It not work doesn´t, the circumflex is temporarily at the end of the text field.

    Another question: if it works, I would like to reuse the ChangeListener onLooseFocus for diefferent TextField. So I would like to know which TextField has lost focus. I tried
    observable.getSoruce(); // like it works with keyEvent
    System.out.println(observable); // -> ReadOnlyBooleanProperty [bean: TextField[id=textFieldDateiname, styleClass=text-input text-field], name: focused, value: false]
    If the id of the source of the ChangeEvent is known...

    Any ideas?

    Thank you

    Lukas

    Edited by: 972241 on 20.11.2012 06:08

    For the latter, you can climb the Observable to a ReadOnlyProperty and call getBean() on it; mount the getBean() call results in a TextField.

    I have no good solution for most of your question. It seems that the default behavior is to restore the position of carat at the beginning of the text, and the listener realizes that runs after your custom listener.
    If the best hack I see is to have a flag that replaces the carat position changes. Set the flag to true on loses focus. Register a listener with the position property of carat, and if the flag is set back to carat at the end (and then disabled the indicator).
    If you want to use the headphones on several fields of text, instead of a flag, have a set of textfields which will have their positions carat substituted changes.

    It's really a hack; I'd like to think that there is a better solution.

    import java.util.HashSet;
    import java.util.Set;
    
    import javafx.application.Application;
    import javafx.beans.property.ReadOnlyProperty;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    
    public class TestFieldFocusTest extends Application {
    
      @Override
      public void start(Stage primaryStage) throws Exception {
        final VBox root = new VBox();
        final TextField tf1 = new TextField();
        final TextField tf2 = new TextField();
    
        final Set overrideNextCaratChange = new HashSet();
    
        final ChangeListener onLoseFocus = new ChangeListener() {
          @Override
          public void changed(ObservableValue observable,
              Boolean oldValue, Boolean newValue) {
            ReadOnlyProperty property = (ReadOnlyProperty) observable ;
            TextField tf = (TextField) property.getBean() ;
            if (!newValue.booleanValue()) {
              tf.end();
              overrideNextCaratChange.add(tf);
            }
          }
        };
    
        final ChangeListener onCaratChange = new ChangeListener() {
          @Override
          public void changed(ObservableValue observable, Number oldValue, Number newValue) {
            ReadOnlyProperty property = (ReadOnlyProperty) observable ;
            TextField tf = (TextField) property.getBean() ;
            if (overrideNextCaratChange.contains(tf)) {
              tf.end();
              overrideNextCaratChange.remove(tf);
            }
          }
        };
    
        tf1.focusedProperty().addListener(onLoseFocus);
        tf1.caretPositionProperty().addListener(onCaratChange);
        tf2.focusedProperty().addListener(onLoseFocus);
        tf2.caretPositionProperty().addListener(onCaratChange);
    
        Button info = new Button("Show info");
        info.setOnAction(new EventHandler() {
    
          @Override
          public void handle(ActionEvent arg0) {
            System.out.printf("Selection: %s (%d characters). Carat position: %d%n",
                tf1.getSelection(),
                tf1.getSelectedText().length(),
                tf1.getCaretPosition());
          }
        });
    
        root.getChildren().addAll(tf1, tf2, info);
        Scene scene = new Scene(root, 100, 200);
        primaryStage.setScene(scene);
        primaryStage.show();
      }
    
      public static void main(String[] args) {
        launch(args);
      }
    
    }
    
  • Help, please! animation of an Image to the top and stay in an elevated position, until the mouse leaves hover

    I have an image I want to animate on hover above him as in this example http://codepen.io/chriscoyier/pen/vDBCI I would like the picture to animate to the top and stay in an elevated position, until the mouse leaves the hover.

    After clicking on the link above, the example is in the lower left corner of the page (it's a red rectangle.  Go over it please and you will see what I want to accomplish)

    If we cannot accomplish this in muse, can I use another Adobe software to create and import in muse?

    Thx for your help!

    Sam

    Try this code

    in HTML

    In your code, I see under style, Body tag is not closed,} is missing, maybe that's the reason.

    Hope this helps

  • Calculation of the position of the slider is not working properly with a sensible step

    Hello

    I already wrote in another thread on this subject, but my problem is slightly different from the other discussion, so here's one more time:

    I want to display a symbol next to the slider. He should stay there as in this example here: http://sandbox.junglecrowd.org/static/publish/web/static.html

    When you use a sensible step (which is essential for my project, because I need width of 100% on all window sizes) ot the symbol placement is dependent on the window size and position on the screen. Here is an example of the problem:

    http://sandbox.junglecrowd.org/responsive/publish/Web/responsive.html

    Then, collecting the coordinates to the breast of EA seems not to be the right way... Or does anyone know a solution to compensate for the changes?

    My idea would be to get the coordinates outside the EA... would it be possible? And in what way?

    .. of course, other solutions are welcome!

    Here is my code... As you can see I am very new to EA and coding...

    Thank you!

    BTW: I read a lot of things in this forum before because of other problems, and I found many solutions: thank you all!

    CompositionReady

    SYM.createsym = function() {}

    var position = sym.$("box").show ();

    position2 var = sym.$("text").show ();

    position. CSS({)

    Top: sym.posY, left:sym.posX

    });

    position2. CSS({)

    Top: sym.posY, left:sym.posX

    });

    };

    Stage.MouseMove

    sym.posX = e.pageX + 30;

    sym.posY = e.pageY;

    SYM.createsym ();

    I discovered a solution now!

    I take the width of the window and make a report with the width of the stage variable... The stageratio then gets multiplied with the details... When resizing the window, variables are recalculated...  Here's a working example:

    http://sandbox.junglecrowd.org/responsive_works/publish/Web/responsive .html

    Here's the code... If anyone knows how to do to improve it please tell me

    CompositionReady

    SYM.xycompensation = function() {}

    var point = sym.$('Stage');

    var parent = sym.$('Stage').parent ();

    var parentWidth = stage.parent () .width ();

    var stageWidth = stage.width ();

    SYM.scaleratio = stageWidth/parentWidth;

    };

    SYM.xycompensation ();

    $(window) .one ("Resize", function() {}

    SYM.xycompensation ();

    });

    sym.infoLabel = function() {}

    var position = sym.$("box").show ();

    position2 var = sym.$("text").show ();

    position. CSS({)

    Top: sym.posY, left:sym.posX

    });

    position2. CSS({)

    Top: sym.posY, left:sym.posX

    });

    };

    Stage.MouseMove

    sym.posX = e.pageX * sym.scaleratio + 30;

    sym.posY = e.pageY * sym.scaleratio;

    sym.infoLabel ();

  • How conervert psd to css and pixel-to-pixel measurement and positioning at the same position in dreamveaw

    How conervert psd to css and pixel-to-pixel measurement and positioning at the same position in dreamveawer?

    The basic answer is that you can't.  Graphics program can export your mockup in html format, but the result is so bad that people get to the top of the page of coding manually.

    The easiest way to convert your drawings into a working Web page is starting with models already included in your package CS6.  I advise to read the article by Steph at this link to help you get started quickly:

    http://www.Adobe.com/devnet/Dreamweaver/articles/css_simple_styling.html>

    G/L

  • Initial position of the vertical scroll bar control

    How to have the scroll bar position and the image centered at the opening. User can then scroll upwards or downwards. Dreamweaver CS 5.5

    http://www.centaursinvietnam.org/history/ihistoryUnitsMap.html

    I noticed that the "Go To" address did not work. So just go to this page on my Web site

    http://www.centaursinvietnam.org/history/ihistoryUnitsMap.html#cuchiline

    And "View Source" in your browser.

    Bruce

Maybe you are looking for

  • How to synchronize the sent folder

    I have Thunderbird on multiple computers. I find that the sent folder is only synchronized with messages sent from this computer. I will like to have the sent folder synchronized on all the computers to the same account. I chose "sent" in the list of

  • R7500v2: No visible Readyshare on several PCs

    I have a Nighthawk X 4 and two computers Windows 10. One is the other WiFi and ethernet. I have a USB key connected to the router. Both have the router appear under network in Windows Explorer as one of the computers is off. When two computers are pu

  • How to shrink SYSTEM. DRV

    T430s Win7 drive factory cloned for SSD SYSTEM. DRV now = 55GB 99% free I understand that system.drv contains the bootloader and cannot be deleted. I would like some tips on how to make system, drv, smaller, including experience with specific softwar

  • The mouse for scrolling in the secondary wheel

    Can someone tell me if there is a way to use the mouse wheel to scroll vertically in a secondary window in 7.1? (I allow the vertical scroll bar, and I focus to the true value.)   I read that it is supposed to work for listboxes, is it supposed to ap

  • Strange E-mail

    I received an email from "hotmail support" ask my user name, password, date of birth, country.  If I did not this that I wouldm lose my account hotmail in 48 hours.  Is - this legimate?