首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jtable鼠标事件弹出2次

jtable鼠标事件弹出2次
EN

Stack Overflow用户
提问于 2016-08-26 16:59:14
回答 1查看 46关注 0票数 0

我创建了一个在表单击时执行的事件,它打开了一个Joption窗格。但问题是joptionpane会弹出两次。请记住,我是在像这样点击(Table0)生成表之后添加事件的,这些表是在从DB检索和一些计算后生成的。

这是事件的代码

代码语言:javascript
复制
 protected void click(JTable table)
{   
    JScrollPane pane=new JScrollPane();



    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {


            if(!combo_chau.getSelectedItem().toString().equals("station"))
                pane.setViewportView(tab_mat(table.getValueAt(table.getSelectedRow(), 2).toString(),table.getValueAt(table.getSelectedRow(), 3).toString()));
                if(combo_chau.getSelectedItem().toString().equals("station"))
                {pane.setViewportView(tab_sta(table.getValueAt(table.getSelectedRow(), 5).toString(),table.getValueAt(table.getSelectedRow(), 0).toString()));
                 if(comboBox_1.getSelectedItem().equals("sans detail"))
                 {   pane.setViewportView(tab_sta_sansdetail(combo_cam.getSelectedItem().toString()));
                    if(combo_cam.getSelectedItem().toString().equals("tout"))
                        pane.setViewportView(tab_sta(table.getValueAt(table.getSelectedRow(), 5).toString(),table.getValueAt(table.getSelectedRow(), 0).toString()));
                 }
                }

            if(table.getModel().getColumnName(((JTable) e.getSource()).getSelectedColumn()).equals("autre") )
            {       int result = JOptionPane.showConfirmDialog(
                    frame, 
                    pane,
                    "Use a Panel",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.PLAIN_MESSAGE);
            }
        }

     });
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-26 17:13:41

请确保在每个表上只调用protected void click(JTable table)方法一次,因为每次调用时都会添加一个新的侦听器。

另一个问题可能是你正在使用已经在鼠标按下时做出反应的mousePressed,你应该考虑使用mouseClicked而不是只在点击一次时才做出反应。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39162339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档