[英]JList selected data from highlighted
What I am trying to do with a JList
is be able to select an index by either scrolling with the mouse or using the keyboard up or down buttons without requiring a key press or mouse click event. 我要使用JList
操作是能够通过使用鼠标滚动或使用键盘的向上或向下按钮来选择索引,而无需按键或单击鼠标事件。 I have tried looking into listeners and I think that's the right direction to go but if someone could put it simply I would appreciate it so much. 我尝试调查听众,我认为这是正确的方向,但是如果有人能简单地说出来,我将非常感激。
//edit. //编辑。
To add more detail here is an example of what i mean, see Halo 3 is high lighted but the stock item name etc is for halo 4 要在此处添加更多详细信息,请参见“光晕3”的突出显示,但库存商品名称等适用于“光晕4”
You need to add a ListSelectionListener
to the ListModel
of the JList
. 您需要将ListSelectionListener
添加到JList
的ListModel
中。 Then when the selection event is generated you invoke your logic to update the two text fields. 然后,在生成选择事件时,您将调用逻辑以更新两个文本字段。
Read the section from the Swing tutorial on How to Write a List Selection Listener for more information and examples. 阅读Swing教程中有关如何编写列表选择侦听器的部分,以获取更多信息和示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.