java – 通过单击位置从JList获取组件
发布时间:2020-12-14 23:46:00 所属栏目:Java 来源:网络整理
导读:如何通过单击位置从JList获取组件? 我有自己的列表单元格渲染器,我插入一些面板和标签. 现在我想得到,例如用户点击的标签. 我尝试了方法list.getComponentAt(evt.getPoint());但它只返回整个JList. 解决方法 我没有测试过这个,但基础知识是…… 使用JList#l
如何通过单击位置从JList获取组件?
我有自己的列表单元格渲染器,我插入一些面板和标签. 我尝试了方法list.getComponentAt(evt.getPoint());但它只返回整个JList. 解决方法
我没有测试过这个,但基础知识是……
>使用JList#locationToIndex(Point)获取元素的索引 可能,像…… int index = list.locationToIndex(p); Object value = list.getModel().getElementAt(int); Component comp = listCellRenderer.getListCellRendererComponent(list,value,index,true,true); comp.setBounds(list.getCellBounds(index,index)); Point contextPoint = SwingUtilities.convertPoint(list,p,comp); Component child = comp.getComponentAt(contextPoint); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |