我的代码jTable1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int select = jTable1.getSelectedRow();
int choi = JOptionPane.showConfirmDialog(null, "Voulez Vous vraiment choisir ce client ?");
if(choi == 0){
Utile.idClient=jTable1.getModel().getValueAt(select, 0).toString();
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}
}
}
});
没有工作:
MyTable
答案 0 :(得分:1)
因为您使用内部类this
指向内部实例。要使用外部实例:
MyFrame.this
答案 1 :(得分:0)
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
"这"指的是MouseListener,而不是框架。
要查找活动窗口,您可以执行以下操作:
Window window = SwingUtilities.windowForCompoent( e.getComponent() );
dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));