What I’m trying to achieve is to “secretly” edit some html code before I paste it into an HTMLEditor. Can anyone think of a way of doing something like this in JavaFX 2?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Normally what you can do is add a
ChangeListenerto a property which is changing (for example aTextArea‘sTextProperty) inspect the new value in the change listener and modify it to something you want. This strategy is not exactly the same as aTransferHandler, but (I think) would work in some places where you would have used aTransferHandlerin Swing. Unfortunately, in the case of aHtmlEditor, you would not be able to use such a strategy becauseHtmlEditortext is not implemented as a listenable property (although there is a request to make it a property in a future JavaFX release: RT-18436).Looking at the JavaFX drag and drop documentation, JavaFX does support a TransferMode which can be queried on reception of a drag event to perform different actions (such as copying, linking or moving data).
Also, if you look at example 6 from the drag and drop documentation, you can see that it is possible to set an onDragDropped event handler for a node which can intercept the
DragEventand take appropriate action at that time (such as setting thehtmlTextof theHtmlEditorto a modified version of the dragged data). If you have difficulty overriding the defaultonDragDroppedfunction of theHtmlEditor, then you could place an event filter on theHtmlEditorwhich allows you to catch, handle and consume the relevant drag event as you wish.