?
Solved

JTable - Pop Up menu compatibility?

Posted on 2003-03-28
5
Medium Priority
?
349 Views
Last Modified: 2013-11-28
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
Comment
Question by:java_gurlx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:ykaganov
ID: 8228783
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
 

Author Comment

by:java_gurlx
ID: 8228972
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
 

Expert Comment

by:CleanupPing
ID: 9058421
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9735365
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
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9784337
This question is PAQed  and no points refunded (of 75).

YensidMod
Community Support Moderator
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
There is a massive demand for content on the web right now, and it doesn't look like it's going to stop any time soon. But, if you are running a business blog, it's not just enough to offer your audience lots of content. It needs to be high-quality…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question