[英]Java - Component Clicked In JPanel
I have a JList<JPanel>
that includes a JCheckBox
and JLabel
. 我有一个
JList<JPanel>
,其中包括JCheckBox
和JLabel
。 I need to find out which one was clicked. 我需要找出单击了哪个。 I am using a
MouseAdapter
. 我正在使用
MouseAdapter
。 I can get the JPanel
with 我可以得到
JPanel
用
int index = locationToIndex(e.getPoint());
getModel().getElementAt(index);
But I can't find a way to determine what Component
in the JPanel
was clicked. 但是我找不到确定单击
JPanel
哪个Component
的方法。
Any help is appreciated. 任何帮助表示赞赏。
Call JList.addListSelectionListener(ListSelectionListener)
. 调用
JList.addListSelectionListener(ListSelectionListener)
。
The ListSelectionListener
provides a ListSelectionEvent
. ListSelectionListener
提供一个ListSelectionEvent
。 See the methods of the event to get access to the 1st and last indices of the user's selection. 查看事件的方法以访问用户选择的第一个和最后一个索引。 See also How to Use Lists in the tutorials for further tips & working source.
另请参阅教程中的“ 如何使用列表”以获取更多提示和工作源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.