JpopupMenu not displaying

hi all,

why the JPopupMenu is not displaying here?

is this line not registering mouseListener

enableEvents(AWTEvent.MOUSE_EVENT_MASK);

import java.awt.AWTEvent;

import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import javax.swing.JMenuItem;

import javax.swing.JPanel;

import javax.swing.JPopupMenu;

import javax.swing.JScrollPane;

import javax.swing.JTable;

publicclass DemoPopUpextends JFrame{

protected JPopupMenu popupMenu =new JPopupMenu();

protected JMenuItem m_mniInsertRow;

protected JMenuItem m_mniInsertScrip;

protected JMenuItem m_mniDeleterRow;

protected JMenuItem m_mniDeleteExpiredScrip;

protected JMenuItem m_mniSetAlert;

JTable tbl =new JTable(100, 8){

public Object getValueAt(int row,int col){

return row+","+col;

}

};

public DemoPopUp(){

m_mniInsertRow =new JMenuItem("Insert a Row");

m_mniInsertScrip =new JMenuItem("Insert a Scrip");

m_mniDeleterRow =new JMenuItem("Delete a Row");

m_mniDeleteExpiredScrip =new JMenuItem("Delete a Expired Scrip");

m_mniSetAlert =new JMenuItem("Set Alert");

popupMenu.add(m_mniInsertRow);

popupMenu.add(m_mniInsertScrip);

popupMenu.add(m_mniDeleterRow);

popupMenu.add(m_mniDeleteExpiredScrip);

popupMenu.add(m_mniSetAlert);

enableEvents(AWTEvent.MOUSE_EVENT_MASK);

JPanel jp =new JPanel();

JScrollPane src =new JScrollPane(tbl);

jp.add(src);

getContentPane().add(jp);

setVisible(true);

pack();

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

publicvoid processMouseEvent( MouseEvent evt )

{

if( evt.isPopupTrigger() )

{

JTable source = (JTable)evt.getSource();

int row = source.rowAtPoint( evt.getPoint() );

int column = source.columnAtPoint( evt.getPoint() );

System.out.println(column);

source.changeSelection(row, column, false,false);

popupMenu.show(evt.getComponent(), evt.getX(), evt.getY());

}

}

publicstaticvoid main(String[] args)

{

new DemoPopUp();

}

}

thanks

daya

[4137 byte] By [dayanandabva] at [2007-10-3 8:33:47]
# 1

> is this line not registering mouseListener

> enableEvents(AWTEvent.MOUSE_EVENT_MASK);

No and you don't need that line.

For general usage of a MouseListener, read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/events/handling.html]How to Use a Mouse Listener[/url]

For specific information on popups, read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup]Bringing Up a Popup Menu[/url] for a working example.

camickra at 2007-7-15 3:41:11 > top of Java-index,Desktop,Core GUI APIs...
# 2
thanks camickr,actually what i think if i use this line enableEvents(AWTEvent.MOUSE_EVENT_MASK);then there is no need of any listener for any componentdaya
dayanandabva at 2007-7-15 3:41:11 > top of Java-index,Desktop,Core GUI APIs...