JList 双击事件的实现

 1.定义JList

2.在JList对象上添加鼠标监控器 (MouseListener)

3.在点击事件被触发以后,判断它在JList中的位置,然后确定击打的次数,根据次数来选择处理的函数。

String data[] = {"red","blue","green"};

JList jList = new JList(data);

jList.addMouseListener(new MouseAdapter() {

        public void mouseClick(MouseEvent e) {

                if(jList.getSelectedIndex() != -1) {

                           if(e.getClickCount() == 1)

                                        oneClick(jList.getSelectedValue());

                          if(e.getClickCount() == 2)

                                        twoClick(jList.getSelectedValue());

        }

}

private void oneClick(Object value) {

               //单击处理   

}

private void twoClick(Object value) {

              //双击处理  

}

你可能感兴趣的:(object,String)