JDK-8094480 : [Skin] Skin reregistration leads to double text typing
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 7u45
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2014-02-25
  • Updated: 2015-06-12
  • Resolved: 2014-03-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u20Resolved
Related Reports
Duplicate :  
Description
I have developed my own subclass of TextField and it uses a skin class which is its own subclass of TextFieldSkin. At some point I register the skin like this

setSkin(new MyTextFieldSkin())

This works just fine. However, this line of code is part of a larger method, and in some cases that method may be executed more than once during an execution of my app. This effectively means I instantiate a new MyTextFieldSkin and assigns it to the TextField, replacing the existing MyTextFieldSkin.

And this is where I have discovered a bug. After setting the skin twice any keyboard input to the TextField is registered twice, so typing the K key adds the characters "kk" to the TextField contents. This is consistent, so if I run this code

setSkin(new MyTextFieldSkin())
setSkin(new MyTextFieldSkin())
setSkin(new MyTextFieldSkin())

and then type the P key once, I get "ppp" ��� three P's, one for each skin. I am guessing the setSkin method forgets to unregister the previous skin.

I do not have the time to build a seperate test app which illustrates the bug, but do not hessitate to ask any questions you might have.
Comments
This is a duplicate of RT-33507, which is part of umbrella issue RT-33520. A workaround is to always check if (getSkin() == null) before setting the skin. In JDK 8, I'm not actually seeing multiple characters being inserted in the text property. This is because the first listener marks the event as consumed, and the following listeners then ignore it. What I do see is that TextField gets multiple skin panes added, each one containing a Text node, and all stacked vertically. This explains the artifacts mentioned in RT-33507. TextFieldSkin should implement the dispose() method, but it probaby won't help until RT-33520 is resolved. This also applies to some other skins, such as SeparatorSkin.
17-03-2014