Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PopupMenu & popupwindow 1

Status
Not open for further replies.

kohinoor2007

Programmer
Mar 21, 2007
69
DE
Hi Guys,


Have some questions regarding invoking a popup menu.Hope some one could give me a hand on this one...
Please see attached Figure as well.





[1]
Have a Table having a certain number of rows.want to create a pop up menu when user selects a cell and rightclicks from that cell.

But I read the following from the java tutorial:

>>To bring up a popup menu ( JPopupMenu), you must register a mouse listener on each >>component that the popup menu should be associated with. The mouse listener must >>detect user requests that the popup menu be brought up.

So is it possible to bring up the popupmenu when rightclicking on a certain cell ,rather than a component(Ofcourse cells belong to the component,but dont want the popup window to come up when right clicking on any cell in the table).How can I achive this behaviour.

[2]After clicking on one of the menuItem from the popupmenu,want a window with some data to be displayed as shown in the attached figure.This window should have scrollbars & each string should be in a different line in this window.
Also the window position or origin should be just below the cell where the right click occured.The window should vanish when selection is made on any other cells.

Would be nice if someone could tell me how these things are to be done.A code snippet would be great....

Thanks
 
You could always add a mouse listener to the JTable in general and this could query the JTable for which cell is currently selected to tailor the popup menu and correctly apply the operations it offers to the user.

Tim
 
Okay tim,So I have to just add the mouselistener to table.But still one thing is not clear to me.

>>and this could query the JTable for which cell is >>currently selected to tailor the popup menu and correctly >>apply the operations it offers to the user.

Is this done automatically or Should I have to do something.For eg:- if the cell is empty,dont want the popup menu to to come up.What should I do here programatically.

How about the 2nd question.Any tips...

 
Use something like the
Code:
getSelectedColumn();
getSelectedRow();
methods on the JTable. You may need to use the
Code:
setCellSelectionEnabled();
method to allow cell selection if you haven't already.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top