Dispatch new Event
Hi everyone.
I'm building an application that has a JTable inside a JScrollPane. Usually when you click the table with the left mouse button it selects the row (in my case). I also have a popup menu that shows up when the right button of the mouse is clicked. Well, this popup menu has to retrieve information from the selected row. The problem is that the row isn't selected. This is my problem: i the row to be selected when i click the right mouse button.
This is the code I'm using:
jTable1.addMouseListener(new java.awt.event.MouseAdapter(){// Setting up the listener
publicvoid mouseClicked(java.awt.event.MouseEvent evt){
jTable1MouseClicked(evt);
}
});
....
privatevoid jTable1MouseClicked(java.awt.event.MouseEvent evt){
if(evt.getButton()==MouseEvent.BUTTON3){
jTable1.dispatchEvent(new MouseEvent(jTable1,
evt.getID(),
evt.getWhen(),
MouseEvent.BUTTON1_MASK,
evt.getPoint().x,
evt.getPoint().y,
evt.getClickCount(),
evt.isPopupTrigger(),
MouseEvent.BUTTON1));
}
}
As you can see I'm trying to "emulate" a click of the left mouse button and just let the table handle it. But it isn't happening.
Every suggestion will be welcomed.
Thank you.
JCruz

