简体   繁体   English

Java Swing中的助记符冲突

[英]Conflicting mnemonics in Java Swing

I'm working on a complex desktop app with multiple tabbed panes for workflow, each one stuffed with different buttons, labels and other UI elements. 我正在开发一个复杂的桌面应用程序,其中包含多个用于工作流的选项卡式窗格,每个窗格都填充了不同的按钮,标签和其他UI元素。 Each of them require a mnemonic defined, and these often come into conflict because of running out of letters to define. 它们中的每一个都需要一个助记符定义,并且由于用尽定义的字母而常常会发生冲突。

I have noticed that on Windows, if there is the same mnemonic defined for two controls, then pressing it will cycle between them, and they activate upon releasing the key. 我注意到在Windows上,如果为两个控件定义了相同的助记符,则按下它将在它们之间循环,并在释放键时激活它们。 With Swing, the mnemonics simply won't activate if you define 2 of them with the same key. 使用Swing,如果使用相同的键定义其中两个,则助记符将不会激活。

Is there a workaround for this? 这有解决方法吗?

My suggestion would be to use a KeyListener and then differentiate the actions based on what tab is showing. 我的建议是使用KeyListener ,然后根据显示的选项卡区分操作。

Pseudo-code : 伪码

public void keyPressed(KeyEvent e){
    //assuming 'O' activates Open button on two different tabs
    if(key == 'O'){
        if(activeTab == tab1)
            doStuff1();
        else if(activeTab == tab2)
            doStuff2();
    }
}

You can find a way to make it work in real code. 您可以找到一种方法使其在实际代码中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM