我在JPanel中使用HTMLEditor时遇到问题。一切正常,但按ENTER键进入新行不起作用。
我的代码:
public class MessageEditor extends JPanel {
private HTMLEditor htmlEditor;
private Scene scene;
private JFXPanel jfxPanel;
public MessageEditor() {
jfxPanel = new JFXPanel();
this.setLayout(new BorderLayout());
loadJavaFXScene();
}
private void loadJavaFXScene() {
Platform.runLater(new Runnable() {
@Override
public void run() {
htmlEditor = new HTMLEditor();
scene = new Scene(htmlEditor, 450, 450);
scene.setRoot(htmlEditor);
htmlEditor.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
logger.debug("KE: " + event);
jfxPanel.setScene(scene);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
add(jfxPanel, BorderLayout.CENTER);
revalidate();
repaint();
}
});
}
});
}
EventHandler处理ENTER键,但编辑器没有输入新行。
KeyEvent [source = HTMLEditor[id=null, styleClass=root], target = WebView@e9bb131[styleClass=web-view], eventType = KEY_PRESSED, consumed = false, character = , code = ENTER]