简体   繁体   English

Java-在JPanel中单击的组件

[英]Java - Component Clicked In JPanel

I have a JList<JPanel> that includes a JCheckBox and JLabel . 我有一个JList<JPanel> ,其中包括JCheckBoxJLabel 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.

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