• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

JTable - Pop Up menu compatibility?

Hi, I'd like to add a pop-up menu to a JTable I have implemented.

Ideally I would like it to respond to each cell (i only have one column list). The context menu should then be able to delete a row or add a new one.

Could any one please point me towards some on-line resources or even if you can give me examples that would be great.

appreciated

java_gurlx
0
java_gurlx
Asked:
java_gurlx
1 Solution
 
ykaganovCommented:
You can add a MouseListener directly to JTable and display the popup whenever someone clicks on a mouse.

If I was writing it, it would look something like this:
MouseAdapter lst = new MouseAdapter() {

  public void mousePressed(MouseEvent evt) {
    checkPopup(evt);
  }

  public void mouseReleased(MouseEvent evt) {
    checkPopup(evt);
  }
 
  // Windows and Unix treat different events as popup triggers
  private void checkPopup(MouseEvent evt) {
    if(evt.isPopupTrigger()) {
      JTable table = (JTable)mouseEvent.getSource();
      Point p = mouseEvent.getPoint();
      int row = table.rowAtPoint(p);
      int col = table.columnAtPoint(p);

      // show popup and do the rest of your logic
      showPopup(row, col);
    }
  }
};

_myTable.addMouseListener(lst);
0
 
java_gurlxAuthor Commented:
hi ykaganov, thanks for the advice.

Could you possibly provide me with a template class that your code will work with?I'm having a little trouble adapting it to mine.

I will increase my points to 150 if you do so.

thanks.

java_gurl.
0
 
CleanupPingCommented:
java_gurlx:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
jimmackCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ - No refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0
 
YensidModCommented:
This question is PAQed  and no points refunded (of 75).

YensidMod
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now