How do I get the character under the cursor?

I'll try to find the best approach/strategy for the character under the cursor in a text node that contains multiple characters, and I was wondering if anyone had any idea of how to go about doing this?

Hello. You can get the character at the cursor location in the text field by adding a listener to the caretPosition property:

        final TextField tf1 = new TextField();
        tf1.caretPositionProperty().addListener(new ChangeListener() {
            public void changed(ObservableValue observable, Number oldValue, final Number newValue) {
                if (newValue != null && newValue.intValue() > 0) {

                    System.out.println("The caracter at cursor is --> " + tf1.getText(newValue.intValue() - 1, newValue.intValue()));

                }
            }
        });

Update:

You ask about text, not a text field. I did not pay attention. Sorry about that.
It can be made to the text too.

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.effect.InnerShadow;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class TextFieldSample extends Application {

    @Override
    public void start(Stage primaryStage) {

        EventHandler mouseEntered = new EventHandler() {
            public void handle(MouseEvent event) {
                System.out.println(((Text) event.getSource()).getText());

            }
        };

        Text h = new Text("H");
        h.setOnMouseEntered(mouseEntered);
        Text e = new Text("E");
        e.setOnMouseEntered(mouseEntered);
        Text l1 = new Text("L");
        l1.setOnMouseEntered(mouseEntered);
        Text l2 = new Text("L");
        l2.setOnMouseEntered(mouseEntered);
        Text o = new Text("O");
        o.setOnMouseEntered(mouseEntered);
        HBox hbox = new HBox();
        hbox.getChildren().addAll(h, e, l1, l2, o);

        VBox root = new VBox();
        root.getChildren().addAll(hbox);

        Scene scene = new Scene(root, 300, 250);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

The next version of javafx8 will be a TextFlow to Word RTF.
A TextFlow simplifies processing.

http://download.Java.NET/jdk8/jfxdocs/JavaFX/scene/text/textflow.html

Published by: shakir.gusaroff on March 2, 2013 19:15

Tags: Java

Similar Questions

  • By creating a form that has several text boxes to a single character on the same line, how can I get the cursor to go in the next text box automatically after inserting a character?

    By creating a form that has several text boxes to a single character on the same line, how can I get the cursor to go in the next text box automatically after inserting a character?

    Create a text field and use the option 'comb n characters.

  • My text box is frozen and has a dotted around her line, how can I get the cursor inside?

    My text box is frozen and has a dotted around her line, how can I get the cursor inside? I work in Indesign CS3, I wrote a page of A4 format with a unique and with a large amount of text inside text box. In the end, I brought a JPEG in the page. Now they have a thin line dotted around them and appear "frozen." I have not seen the dotted line instead of the line before usual text box.

    Points: The text box is not locked, the layer is not locked. Nothing on the page goes live with command + A to select.

    It happened between the Time Machine backups so that I can not restore.

    All I need are the captured keystrokes.

    What can happen when you put the JPEG, I myself can I have moved that file folder, a larger file, on the desktop, then placed the JPEG.

    Re-opening Indesign didn't work; restart did not work.

    Solutions appreciated.

    The dotted lines mean that your items are on a master page and not a document page.

  • How do you get the cursor to move in Dreamweaver CS5?

    Im trying to get the cursor to move to the right or up and down, but he still left. IM new to dreamweaver for any advice would be much appreciated.

    Thanks in advance

    Im trying to get the cursor to move to the right or up and down, but he still left. IM new to dreamweaver for any advice would be much appreciated.

    You mean the caret blinking (slider) located in the upper left corner when you're faced with a blank page?

    If tthat's what you mean, then you have not.

    The first acts of Dreamweaver over to a wordprrocessor (it is NOT a word processor) a desktop publishing application that you can just click anywhere and insert content.

    You need to learn something about HTML and CSS to understand how to use DW.

    Good starting point: http://www.w3schools.com/

    If you meant something else, please advise.

  • In Illustrator, how can I get the cursor type to effectively indicate WHERE the guy is going to start?

    I don't understand. What is the point of having a cursor type at all if the cursor position doesn't look like whatever the point type will begin in? I checked all the Options in the type menu and any leader is zero, so there is no lag anywhere, but when I click on a particular spot on the page, it's because that's where I hope to see the type. What a laugh! No placement type correct, will never be. It must be scooted in place. using the arrow. Is it possible to make the entry point makes it a resemblance to the point ' by clicking on '?

    I don't see a problem:

    Your paragraph palette has something inside in addition to zeros? My guess is that you have left a big indent in the first field.

  • I'm a manuscript, PDF, editing files on my ipad.  Try to get the cursor to allow me to edit the text, how do?

    I'm editing a manuscript, aPDF, on my iPad.  How can I get the cursor appears so I can edit the words and phrases in the manuscript?

    I agree with TSN, but if you insist, go to tools > edit PDF.

  • in windows 7 when you right click on how do you get the little line under the letter of the you can click on to make it open Windows 7

    in windows 7 when you right click on how do you get the little line under the letter of the you can click on to make it open Windows 7

    Example when you right click on a program, you can see Open if you click o the file opens, it was in XP, but not in 7

    That's what you want.

    1 - Open "Control Panel" and go to accessibility.

    2 - click make the keyboard easier to use.

    3. the title of 'Make it easier to use keyboard shortcuts' tick the box 'Underline access keys and keyboard shortcuts' and click 'Ok '.

    Oh sure, it could be useful.

  • How can I get the tabs colorful to use different distinct colors for 2 gmail accounts?

    Under Firefox 29.0.1 iMac OSX 10.9.3. I have multiple Google accounts: 2 1 Google Calendar and gmail accounts. Colorful tabs add-on will allow me to choose a color for a gmail account, but it also uses this same color for the other gmail account. How can I get the different colors on 2 gmail accounts?

    In addition, colorful tabs is also the same for my homepage (google.com) and my google calendar. How can I get different colors on these 2?

    Personally, I use 'Fabtabs' for my mozilla FireFox.

    https://addons.Mozilla.org/en-us/Firefox/addon/FabTabs/

    This add-on has problems like that when I use it.

  • How can I get the back toolbar that says "file, editing, history, tools, etc.?

    How can I get the back toolbar that says "file, editing, history, tools, etc.?

    Don't see the menu bar (file, publishing, display, history...) (Help)? Hold down the key (key in OSX) and press the following letters in this exact order: V T M
    The bar of menus must now appear permanently, unless you turn it off again (view > toolbars). Turn on/off the menu bar is a new feature in version 3.6.
    See the other bars under view > toolbars. Click on one of them will place a check mark (display) or remove the check mark (not shown).
    To display the status bar, display, and then click status bar to place a control mark (display) or remove the check mark (not shown).

    • If items are missing then see if you can find them in the view > toolbars > customize window.
    • If you see the item in the window customize then bring her back in the window, customize the Navigation toolbar.
    • If you do not see this item then click Restore default set in the view > toolbars > customize window.
  • How can I get the opening for an enlarged screen screen

    Original title: opening screen

    How can I get the opening for an enlarged screen screen

    If you are talking about an Internet Explorer page, three options.
     

    1: take the corners of the window and drag it to the format full screen. Do not use to expand. Close all other windows first via the taskbar and the latter. Windows will remember the size of the last closed window the next time that you open the program.
      
     
    2: any shortcut you use to launch the window, right-click, and select Properties. Under the 'Run' drop-down list, choose "expanded".
     
     

     
     
  • When I go to a favorite websight how can I get the user id and the password to open the view without having to put in me? Barry was soon

    When I go to a favorite websight how can I get the user id and the password to open the view without having to put in me? Barry was soon

    Hi Barry,.

    Please contact Microsoft Community.

    It would be great if you can answer the following question:

    What browser you use on the computer?

    If you are using Internet explorer, I suggest you to follow these steps to turn on the AutoComplete feature and check if it helps:

    (a) open Internet Explorer.

    (b) click on the Tools button and then click on Internet Options.

    (c) click on the content tab.

    (d) under AutoComplete , click settings.

    (e) check the address bar, Forms, usernames and passwords on formsand ask me before saving passwords check boxes.

    (f) click OKand then click OK again.

    Let us know if this can help, and if you need further assistance.

  • How can we get the details of the traffic for the spaces for example, users access report by place (all users)

    How can we get the details of the traffic for the spaces for example, users access report by space (for all users), DB tables can be used to get information, such as for example: users who have logged in - never

    You can use analytics. WebCenter Analytics comes with a number of events out-of-the-box for which it brings together measures which are very useful.

    You can check in the WebCenter Analytics database schema. WebCenter Analytics Dashboards are present in the scheme of ACTIVITIES and are modeled in the form of a star schema.

    The schema includes 2 types of tables. FACTS analytical tables are used to store instances of specific events. For each event, a specific FACT table is present, for example for page views, the views of space, connections and so on. These tables contain a timestamp for the moment, that the event is occurred and integer ID these descriptive reference data stored in DIMENSION tables.

    DIMENSION tables contain descriptive information about the entities associated with events. Size examples are pages, applications, groupspaces, users and so on.

    See the details of the table all the under http://docs.oracle.com/cd/E23943_01/webcenter.1111/e10148/jpsdg_app_aschema.htm#JPSDG10767

    If you want to custom event.that track, as you can get. see this blog entry

    Quobell technology - portal WebCenter: WebCenter Analytics: define and save custom events

  • Recently switched from PC to Mac. I have the CD for the CS6 Adobe Creative Suite for Mac and PC. How can I get the serial number of the CD Mac OS with no disk drive?

    Recently, I switched from PC to Mac. On my PC, I got the Adobe Creative Suite Design & Web Premium (academic edition) CS6. I bought the product through my school and have two installation CD, for Windows and Mac.

    I try now to download this product on my new Macbook, but do not have a hard drive. When I check my saved items, it says that I have the Creative Suite CS6, but under the platform, he said "Winner" and serial number is for Windows product. Of course, this won't work for my Mac OS.

    So my question is, how do I get the serial number of the installation CD Mac OS with no disk drive? I guess that the numbers are different because when I put the Windows product number in the install window on my Mac, it does not work.

    So my question is, how do I get the serial number of the installation CD Mac OS with no disk drive?

    You use this procedure to share your serial number CS6 win to Mac CS6.

    Exchange a product Adobe of a different version of the language or platform

    Download the Installer application download Adobe Creative Suite 6

  • How can I get the overlay?

    I don't have the original image, but if I did, how I would get the effect? It looks like a simple purple overlay but I know that it is impossible, there is more that that! If I had a picture and and the superimposition of ovrlay, how would you suggest I get a result similar to this?

    Thank you!

    1.jpg

    Hello

    Not sure you if you are serious or not. This seem's a brush of smoke.

    Google search for: photoshop, smoke brushes

    Once applied to a layer, use one of the mixing mod layer to apply the under layer.

    Stone

  • How can I get the HBA iScsi IQN name

    How can I get the HBA iScsi IQN name?

    How to use the following object:

    I tried this:

    var myVcHostInternetScsiHba = new VcHostInternetScsiHba();

    IQN = VcHostInternetScsiHba.iScsiName;

    But it does not work.

    regards Denis

    findiSCSIDevice action () returns the string iSCSI device, and not as an object.

    You can duplicate this action (say under a name findiSCSIName) and change its script code by replacing the following line:

    return busAdapter.device;
    

    with

    return busAdapter.iScsiName;
    

    and then use it in your workflow and actions of something like

    var hbaScsiName = System.getModule("com.vmware.library.vc.storage").findiSCSIName(host);
    
  • How do you get the path of the data store or the URL of a virtual disk in vRealize Orchestrator?

    I need to eager zero a virtual disk while building a virtual machine. I found the eagerZeroVirtualDisk_Task() under VcVirtualDiskManager function, which takes in 2 parameters:

    name - (String) the name of the disk, is a path to the data store or a URL pointing to the virtual disk that needs to be inflated.

    Data Center - (VcDatacenter) if the name is a path of data store, the data center for the path of the data store. Not necessary when called directly on ESX. If not specified on a call to VirtualCenter, the name must be a URL.

    How can I get the correct path of data store given the virtual disk? I intend to iterate through the features of the virtual machine to get the disks.

    Thank you!

    Actually figured out how to get the path of the data store, and how a drive zeros. In case it is useful to share the code here:

    var vimHost = vm.vimHost; VM instanceof VCVirtualMachine

    var vDiskMgr = vimHost.virtualDiskManager;

    for each disk

    var features = vm.config.hardware.device;

    for each {(dev var in devices)

    dev.backing contains a lot of useful things...

    If (dev instanceof VcVirtualDisk) {}

    a disc!

    var dsPath = dev.backing.fileName;

    System.log ("path of disk:" + dsPath);

    Data var Center =

    System.getModule('com.vmware.library.vc.datastore').getDatacenterForDatastore (dev.backing.datastore);

    var vcTask = vDiskMgr.eagerZeroVirtualDisk_Task (dsPath, datacenter);

    wait

    var waitResult =

    System.getModule('com.vmware.library.vc.basic').vim3WaitTaskEnd (vcTask, true, 5);

    }

    }

Maybe you are looking for

  • AT200 connection to a PC Windows XP

    Hi comrades Toshiba users. I tried to connect my AT200 tablet to my PC with a microUSB/USB cable. PC running XP SP3 and WMP 11 is installed. When I connect, PC will not recognize the device due to missing driver... (She appears under AT200 in the lis

  • Error 200220 CRIO 9081 and data acquisition modules

    Hello I try to use a CRIO 9081 with NI9206 modules. Max recognize the chassis, but not the module. When I try to add an acquisition of data associated with the NI9206 in Veristand, 200220 error message seems.

  • Wanted: Wireless blue light always on

    Hello I have a new Hp envy laptop and up to a few weeks with the F12 I could turn on/off my wireless connection. Now its always blue, even when I try disconect it it shows the blue ligh only a flight mode message puppies say turn off/on. How can I so

  • Problem of transparency with a compass 2D plot

    Hello I use a compass 2D field to view the joint angle. I have the desire to have the plot area and the transparent border of the chart, the plots are so over a picture on my wall and nothing else is visible. So that I can put it in the editor contro

  • Fax Server help

    We have our PRI come to our 2950 some of the DID attached to the PRI are to our server, GFI Faxmaker.  This server is using a Brooketrout TR114 + P4C card 2 ports boot loop 0-1 and 2 ports DID 2-3 ports.  On the 2950 router I have a port 0 of the bro