我创建了一个在表单击时执行的事件,它打开了一个Joption窗格。但问题是joptionpane会弹出两次。请记住,我是在像这样点击(Table0)生成表之后添加事件的,这些表是在从DB检索和一些计算后生成的。
这是事件的代码
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);
}
}
});
}发布于 2016-08-26 17:13:41
请确保在每个表上只调用protected void click(JTable table)方法一次,因为每次调用时都会添加一个新的侦听器。
另一个问题可能是你正在使用已经在鼠标按下时做出反应的mousePressed,你应该考虑使用mouseClicked而不是只在点击一次时才做出反应。
https://stackoverflow.com/questions/39162339
复制相似问题