I was trying to do some experiments with JavaFX’ HTMLEditor component. I used the following code(excerpt):
fxPanel=new JFXPanel();
Platform.runLater(new Runnable() {
@Override
public void run() {
Group group = new Group();
scene = new Scene(group);
fxPanel.setScene(scene);
view = VBoxBuilder.create().build();
group.getChildren().add(view);
edit = HTMLEditorBuilder.create().build();
// toolPane = TabPaneBuilder.create().minHeight(60d).build();
//toolPane.getTabs().add(new Tab("Allgemein"));
view.getChildren().add(edit);
}
});
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jPanel1.add(fxPanel);
}
});
It works fine so far with one important exception – i can’t use the return key for a BR – it seems just to be ignored. There is no reaction on this key at all. As far as i could see, any other key works as expected.
I noticed that CTRL–M works where Enter doesn’t. So I just worked around this by putting a
KeyListeneron the JFXPanel, changing theKeyCharfrom 10 to 13 and reposting the event to the System Event Queue. This may stop working as intended later on if the HTMLEditor starts responding to both ENTER and CTRL–M though.Anyone have a better idea for now?
Edit: I found another way to get the desired effect is to install a custom
KeyEventDispatcheron the current keyboard focus manager like so:This has the advantage of changing the original
KeyEventrather than posting a new one afterwards, so that ifHTMLEditorwere to start responding to Enter events we wouldn’t be doubling up.