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
KeyListener
on the JFXPanel, changing theKeyChar
from 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
KeyEventDispatcher
on the current keyboard focus manager like so:This has the advantage of changing the original
KeyEvent
rather than posting a new one afterwards, so that ifHTMLEditor
were to start responding to Enter events we wouldn't be doubling up.I still see this problem with Oracle JDK 10. Peeking into the
HTMLEditorSkin
, there is aCommand.INSERT_NEW_LINE
, but it is not performed when pressing 'Enter'. In principle, there is API for executing aCommand
, and that could be invoked from a key event filter, but the API is private.The following is a hack around this limitation. It "works", but it is of course a hack that might break with future updates of JavaFX:
I found out that it's an already known bug in JavaFX.
https://javafx-jira.kenai.com/browse/RT-33354
and
http://javafx-jira.kenai.com/browse/RT-20887
But FYI, it was resolved as "Won't Fix" for JavaFX 2.2. There is no problem in JavaFX 8.