码迷,mamicode.com
首页 > 其他好文 > 详细

e783. 监听对JList中项双击和三击

时间:2018-09-06 10:56:54      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:oca   string   center   location   ems   sel   void   width   related   

 // Create a list
    String[] items = {"A", "B", "C", "D"};
    JList list = new JList(items);
    
    // Add a listener for mouse clicks
    list.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            JList list = (JList)evt.getSource();
            if (evt.getClickCount() == 2) {          // Double-click
                // Get item index
                int index = list.locationToIndex(evt.getPoint());
            } else if (evt.getClickCount() == 3) {   // Triple-click
                // Get item index
                int index = list.locationToIndex(evt.getPoint());
    
                // Note that this list will receive a double-click event before this triple-click event
            }
        }
    });

 

Related Examples

e783. 监听对JList中项双击和三击

标签:oca   string   center   location   ems   sel   void   width   related   

原文地址:https://www.cnblogs.com/borter/p/9596136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!