gpt4 book ai didi

java - 如何为 JTextField 映射选项(Mac 键盘)的操作?

转载 作者:行者123 更新时间:2023-12-01 23:20:55 28 4
gpt4 key购买 nike

看起来选项 up 只能用 AWT 捕获(即添加关键监听器)。有没有一种方法可以做到这一点,而不必使用 AWT?

最佳答案

JTextField 的 Mac OS X UI 委托(delegate)不会将 alt 绑定(bind)到任何 Action 。您可以自由地将组合绑定(bind)到您选择的任何操作。如图How to Use Key Bindings ,下面的示例将 alt 绑定(bind)到为 JTextField 定义的现有 "caret-begin-line",其中将插入符号移至行首。

final JTextField jtf = new JTextField("Test");
jtf.getInputMap().put(
KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK),
"caret-begin-line");

可以找到更多示例 here 。如引用的键绑定(bind)实用程序here所示, JTextField 按名称将以下 WHEN_FOCUSED 操作绑定(bind)到指定的键。

beepcaret-backward                LEFT, KP_LEFT, ctrl Bcaret-begin                   ctrl P, meta UP, meta KP_UP, HOMEcaret-begin-line              KP_UP, ctrl A, UP, meta KP_LEFT, meta LEFTcaret-begin-paragraphcaret-begin-wordcaret-downcaret-end                     ctrl N, END, meta KP_DOWN, ctrl V, meta DOWNcaret-end-line                DOWN, meta KP_RIGHT, ctrl E, meta RIGHT, KP_DOWNcaret-end-paragraphcaret-end-wordcaret-forward                 RIGHT, ctrl F, KP_RIGHTcaret-next-word               alt KP_RIGHT, alt RIGHTcaret-previous-word           alt KP_LEFT, alt LEFTcaret-upcopycopy-to-clipboard             meta C, COPYcutcut-to-clipboard              CUT, meta Xdefault-typeddelete-next                   DELETE, ctrl Ddelete-next-word              alt DELETEdelete-previous               BACK_SPACE, ctrl Hdelete-previous-word          alt BACK_SPACE, ctrl Wdump-modelinsert-breakinsert-contentinsert-tabnotify-field-accept           ENTERpage-downpage-uppastepaste-from-clipboard          meta V, PASTErequestFocusselect-all                    meta Aselect-lineselect-paragraphselect-wordselection-backward            shift LEFT, shift KP_LEFTselection-begin               shift meta KP_UP, shift meta UP, shift HOMEselection-begin-line          shift UP, shift meta KP_LEFT, shift KP_UP, shift meta LEFTselection-begin-paragraphselection-begin-wordselection-downselection-end                 shift meta DOWN, shift meta KP_DOWN, shift ENDselection-end-line            shift meta KP_RIGHT, shift DOWN, shift KP_DOWN, shift meta RIGHTselection-end-paragraphselection-end-wordselection-forward             shift KP_RIGHT, shift RIGHTselection-next-word           shift alt KP_RIGHT, shift alt RIGHTselection-page-down           shift PAGE_DOWNselection-page-left           shift meta PAGE_UPselection-page-right          shift meta PAGE_DOWNselection-page-up             shift PAGE_UPselection-previous-word       shift alt LEFT, shift alt KP_LEFTselection-upset-read-onlyset-writabletoggle-componentOrientation   shift ctrl Ounselect                      meta BACK_SLASH

关于java - 如何为 JTextField 映射选项(Mac 键盘)的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30784939/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com