public class CustomizedHTMLEditor extends HTMLEditor
{
public CustomizedHTMLEditor()
{
addEventFilter(KeyEvent.KEY_RELEASED, event -> {
if (event.getCode() == KeyCode.U && event.isAltDown()) {
System.out.println("Alt+U is pressed");
event.consume();
event.isShortcutDown();
final KeyCode platformShortcutKey = Toolkit.getToolkit().getPlatformShortcutKey();
System.out.println(platformShortcutKey.getName());
}
});
}
}
public class CustomizedHTMLEditorMain extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override public void start(Stage primaryStage)
{
CustomizedHTMLEditor customizedHTMLEditor = new CustomizedHTMLEditor();
customizedHTMLEditor.setFocusTraversable(true);
customizedHTMLEditor.requestFocus();
customizedHTMLEditor.toFront();
primaryStage.setScene(new Scene(customizedHTMLEditor));
primaryStage.show();
}
}
public class CutomizedHTMLPanel extends JDialog
{
CutomizedHTMLPanel()
{
PlatformImpl.startup(() -> {
});
PlatformImpl.runAndWait(() -> {
final JFXPanel jfxPanel = new JFXPanel();
jfxPanel.setScene(new Scene(new CustomizedHTMLEditor()));
add(new JPanel().add(jfxPanel));
pack();
});
}
public static void main(String[] args)
{
final CutomizedHTMLPanel panel = new CutomizedHTMLPanel();
panel.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
panel.setVisible(true);
}
}
当我在编辑器中按ALT + U时:
在过程1中,事件已成功使用,并且在编辑器中未键入Character(在这种情况下为“ U”)。
在过程2中,在编辑器中键入Character。
我想在进程2中使用快捷键ALT + U,当我们按ALT + U时,不应键入任何字符。