-2

on TableHeader, I try to make a right click with the mouse as follow :

tableHeader.click(MouseEvent.BUTTON3);

but this is not working, have you any idea/suggestion ?

thanks,

Ashkan Aryan
  • 3,504
  • 4
  • 30
  • 44
lola
  • 5,649
  • 11
  • 49
  • 61

1 Answers1

3
  • if it is because you want to show a popupmenu then you can do it like this::

    popupMenu.show(tableHeader, 0, 0);


  • if it is because you want to get into a mouselistener like:

    class MyMouseListener implements MouseListener{
    @Override
    public void mouseReleased(MouseEvent arg0) {
        if(SwingUtilities.isRightMouseButton(arg0)){
            //my code
        }
    }
    //...
    

then you can put your code into a method and open the method

 //open the method:
 myMouseListenerReplacement();


//the method
private void myMouseListenerReplacement(){
 //My code
}
Neifen
  • 2,546
  • 3
  • 19
  • 31
  • 1
    -1 (assuming the OP indeed is targeting a Swing JTableHeader) a) if you recomment a JPopupMenu - which is good - then the easiest way to install it is as the header's componentPopupMenu b) if you insist on going the ol' stony path, it's wrong in opening on released (see snoracle's tutorial to learn the correct way) c) don't use the mouseButton constants directly, always go through SwingUtilities.isXXButton – kleopatra Sep 12 '11 at 11:30
  • I think the OP want to simulate a mouseevent and then catch it. // what is snoracle's tutorial?? – Neifen Sep 12 '11 at 11:44