-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10710e3
commit 33c570c
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package javafx.embed.swing; | ||
|
||
import java.awt.event.InputMethodEvent; | ||
import java.lang.reflect.Field; | ||
|
||
import com.sun.javafx.embed.EmbeddedSceneInterface; | ||
|
||
public class CustomJFXPanel extends JFXPanel { | ||
|
||
public CustomJFXPanel() { | ||
super(); | ||
|
||
Field f; | ||
try { | ||
f = this.getClass().getSuperclass().getDeclaredField("scenePeer"); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Siedlerchr
Author
Member
|
||
f.setAccessible(true); | ||
|
||
} catch (NoSuchFieldException | SecurityException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
@Override | ||
protected void processInputMethodEvent(InputMethodEvent e) { | ||
if (e.getID() == InputMethodEvent.INPUT_METHOD_TEXT_CHANGED) { | ||
sendInputMethodEventToFX(e); | ||
} | ||
|
||
super.processInputMethodEvent(e); | ||
} | ||
|
||
|
||
private void sendInputMethodEventToFX(InputMethodEvent e) { | ||
String t = InputMethodSupport.getTextForEvent(e); | ||
|
||
int insertionIndex = 0; | ||
if (e.getCaret() != null) { | ||
insertionIndex = e.getCaret().getInsertionIndex(); | ||
} | ||
|
||
|
||
EmbeddedSceneInterface scenePeer = (EmbeddedSceneInterface) f.get; | ||
scenePeer.inputMethodEvent( | ||
javafx.scene.input.InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, | ||
InputMethodSupport.inputMethodEventComposed(t, e.getCommittedCharacterCount()), | ||
t.substring(0, e.getCommittedCharacterCount()), | ||
insertionIndex); | ||
} | ||
} |
You can also override
setEmbeddedScene
to get a reference toscenePeer
, that is: