LWUIT 选项卡导航/列表焦点问题
我在表单顶部嵌入了 3 个“TABS”。每个选项卡都有一个“列表”。每当我将焦点从一个选项卡更改为另一个选项卡时,我希望我的列表具有焦点。如何确保我的列表始终具有焦点? 我使用 gameKeyEvents 进行导航。我已在表单中添加了一个用于游戏关键事件的 actionListener。我无法覆盖表单的 keyReleased() 方法,因为我需要向表单添加一个操作侦听器(它也包含其他命令)。
我尝试重写“Tabs”类的 keyreleased() 方法,但这不起作用(为什么?)。什么也没发生。
Tabs holder = new Tabs()
{
public void keyReleased(int keyEvent)
{
System.out.println("key release is working"); // this statement does not work
}
};
当我通过左右键导航来移动选项卡时,我的列表失去焦点(它们的选择显示为褪色),而在其他时候它们保持焦点(它们的选择显示为实体。) 如何确保我的列表始终具有焦点?这对于我的程序的运行非常重要。我已附上快照。请帮忙。
请参阅附图。
在图 1 中,您将看到列表项 3 突出显示。现在,如果我按左/右/下游戏键...焦点将从列表中消失并转到第三位置的选项卡。我想防止这种情况发生。 (无法发布图像,因为我是新用户。请检查链接)
I have embedded 3 'TABS' on top of a form. Each tab has a 'LIST'. Whenever I change focus from one tab to another, I want my lists to have focus. How do I ensure that my lists always have focus?
I navigate using gameKeyEvents. I have added an actionListener to my form for game key events. I cannot override the keyReleased() method of the form as I need to add an action listener to my form(it contains other commands too).
I tried overriding the keyreleased() method of my ‘Tabs’ class , but thats not working(WHY??). Nothing happens.
Tabs holder = new Tabs()
{
public void keyReleased(int keyEvent)
{
System.out.println("key release is working"); // this statement does not work
}
};
When i shift tabs by navigating through left and right keys, my lists lose focus (their selection appears faded) and at other times they hold focus (their selection appears solid.)
How do I ensure that my lists always have focus? This is very essential for my program to work. I have attached the snapshots. Please assist.
Please see the attached pictures.
In picture 1, you will see that the list item 3 is highlighted. Now, if I press the left/right/down game keys ...the focus disappears from the list and goes to the tab at 3rd position. I WANT TO PREVENT THIS. (not able to post images cuz am a new user. please check the links)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
派生 Form 并重写
keyReleased/keyPresed
以检测游戏键右/左。当你得到左右键时,永远不要调用 super (在其他情况下总是调用 super )。
在
keyPressed
方法中,如果您向右/向左移动,只需切换选项卡并为适当的列表调用requestFocus()
方法。您需要从 Tabs 组件获取选项卡按钮并将它们设置为 focusable false 以防止列表失去焦点。
Derive the Form and override
keyReleased/keyPresed
to detect game key right/left.When you get a right or left key never call super (always call super for other cases).
In the
keyPressed
method if you get right/left just switch a tab and call therequestFocus()
method for the appropriate list.You need to get the tab buttons from the Tabs component and set them to be focusable false to prevent the list from losing its focus.