Re: different jpopup menus items depending on content in a Jtable
cell
chiuwingsze@gmail.com a 9crit :
Hi,
Is it possible if a popup menu have different items in it, depending on
the content of a jtable cell??
I would be greatful if any one could point me in the right direction.
Thanks
Venus
jtable.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
if (evt.isTrigerPopup())
doPopup(evt);
}
public void mouseReleased(MouseEvent evt) {
if (evt.isTrigerPopup())
doPopup(evt);
}
private void doPopup(MouseEvent evt) {
JPopupMenu jpm = getPopupMenu(evt);
if (jpm != null)
jpm.showComponenent(evt.getSource(), evt.getPoint().x,
evt.getPoint().y);
}
private JPopupMenu getPopupMenu(MouseEvent evt) {
int row = jtable.rowAtPoint(evt.getPoint());
int column = jtable.columnAtPoint(evt.getPoint());
if (row < 0 || column < 0)
return null;
JPopuMenu jpm = new JPopupMenu();
Object o = jtable.getValueAt(row, column);
if (testOn(o)) {
jpm.add(...);
}
...
return jpm;
}
});