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

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 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.

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

    ]]>




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

  • How can I cange positions of the toolbars?

    I reinstalled Firefox after my hard drive crashed and the position of the upper toolbar (open tabs) is higher than the bar of menus (?) and I prefer the tabs to be below the menu bar. In general, how to change the location of the bars.

    In addition, the dark background is difficult for me to see and would get back to lighter I had before. So, how to customize the background of the bar colors?

    Thank you.

    There is an add-on very full which can customize many aspects of the interface, called Classic theme restaurateur. You can install it from the site of modules here:

    https://addons.Mozilla.org/firefox/addon/classicthemerestorer/

    To change the settings, you can use the Options button for the extension on the page modules. Either:

    • CTRL + SHIFT + a
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click Extensions. Then on the right side, find classic theme restaurateur.

  • 19.02 Firefox breaks the position of the background image.

    Hi, I have a jQuery plugin that worked well until I downloaded Firefox 19.02 now the Image slider does not work.

    More precisely the position of backgroundImage doesn't seem to work. Instead of each piece of the picture being selected using a specific and different up and left (x and is position on the Image) all the pieces are showing the top left corner! It worked well in the earlier version of Firefox and still work on the latest versions of Google Chrome, Safari and Opera.

    Appreciate any help you can offer.

    TC

    It's logical. If Math.abs (yPos) works, then yPos cannot be a string, and therefore cannot contain units.

  • Position of the button close the tab tab

    Just updated to 17 of Firefox on my Windows 7 PC. The close tab buttons are now on the left side of the tab instead of the right side. How can I move them back on the right side? I can't find other help on this and tried to play with: config userchrome, but nothing is. I can change the color, add a button in the bar, but does not affect the positioning of the buttons close the tab on the tabs themselves.

    Help!

    You have the module / theme / userstyle installed that controls tab behavior? You can resolve this problem by restarting with disabled modules. You can also reset firefox who, most likely, your problem will be solved.

  • How can I get Firefox back to the same position on the web page

    How can I configure Firefox to return to the same position on the web page

    Wait until Firefox finishes loading web page. Then it will be automatically the position value when you were leaving the web page

  • How can I change the position of the tab bar?

    I can't just get used to the tab bar is on top in Firefox 4. I continue to close open pages by clicking the Favorites menu bar. How can I exchange the position of the two bars?

    Right-click on a toolbar, and then click the entry "Tabs" at the top to deselect the it.

  • Portege M780-106 - the mouse pointer position of the stylus trolling

    Question re Toshiba portege M780-106 touch screen laptop:
    We have a problem with the mouse, the position of the stylus trolling.

    This gap considerably increases the speed of the increase in movement of the stylus.
    As we had a task of monitoring with the stylus it is problematic.

    We run the task in Windows 7 using python 2.6 with mainly pygame library functions.
    Is there a way to disable the process that produces this discrepancy between stylus pointer and mouse?

    Any help much appreciated!

    Best
    Steve

    The CPU is running in performance mode? There may be a delay because the eco mode is activated, or the speed of the CPU has strangled at low speed.

  • Firefox remember its position of the window on my monitors when closing and re-opening.

    Before the latest updates firefox remember the position of the window when he was finally stop. Now, it still load upper left full screen on my first monitor.

    Win7, especially in XP mode because I don't like aero.

    I move Firefox to the monitor I want.
    

    Expand it to full size.
    Take the title bar and knocking it against the top of the screen.
    When the outline appears, let go.

  • Why am I all of these positions of the community in my email?

    Why am I all of these positions of the community in my email?  There are hundreds of them.

    You are subscribed to these tips. Go to each of the areas that you do not want to receive email from and click the button in the upper right corner. If you run the ad-blocking software, you may need to temporarily disable.

    If you wish, you can instead click here and completely turn off notifications by e-mail.

    (139647)

Maybe you are looking for

  • New cases of tuberculosis page does not properly.

    Some time ago, my grandson downloaded something on my computer that has installed the search engine of Babylon to my computer. It replaced the new page tab. I removed the Babylon of my machine, at least that I could find, but the new tab on page load

  • Photo Source other than Facebook/Twitter?

    My syncs to gmail account with my OSX address book. Both have a collection of photos that I have accumulated over the past 10 years for each of my contacts. On my Google Nexus One, I could use these images to show against the contacts, when people ca

  • PowerEdge 2950-second map PERC to connect to PowerVault 220 s

    Hello I have a PowerEdge 2950 unit (Service Tag # NOTE from the ADMIN: maintain the label removed by privacy policy >) and PowerVault 220 s unit (Service Tag # NOTE from the ADMIN: maintain the label removed by privacy policy >). I would like to know

  • Balancing the vCenters

    HelloIs it possible to balance the load of multiple vCenters?I worked with vCenter heartbeat, but I'm looking for a solution that can provide an active state of the vCenters of guaranteed horizontal scalability.Thank you

  • Impossible to import files in LR6 help

    I have been using the opening. I bought LR6 for Mac. opening files imported correctly. However, I can't import from memory card. I get this message "the following files were not imported because they could be read DSC_1790.JPG (2); HELP DSC_1790.NEF.