Skip to content

Commit

Permalink
WIP custom jfxpanel hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Aug 17, 2017
1 parent 10710e3 commit 33c570c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/main/java/javafx/embed/swing/CustomJFXPanel.java
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.

Copy link
@tobiasdiez

tobiasdiez Aug 18, 2017

Member

You can also override setEmbeddedScene to get a reference to scenePeer, that is:

        private EmbeddedSceneInterface scenePeer;

        @Override
        public void setEmbeddedScene(EmbeddedSceneInterface embeddedScene) {
            scenePeer = embeddedScene;
            super(embeddedScene);
         }

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Aug 18, 2017

Author Member

Not possible as this is in an subclass which implements an interface ARgh!

This comment has been minimized.

Copy link
@tobiasdiez

tobiasdiez Aug 18, 2017

Member

Sorry, I don't understand your remark...what is not possible and why?

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Aug 18, 2017

Author Member

The method is in an subclass which implements an interface, so no super calls possible

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

0 comments on commit 33c570c

Please sign in to comment.