Results 1 to 2 of 2

Thread: popup menus - HELP!!

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45

    Question popup menus - HELP!!

    I have a JTree that looks something like this:
    Code:
    A
    --B
    ----1
    ----2
    ----3
    --C
    ----1
    ----2
    ----3
    I want the user to be able to click on ANY child of B, (1,2,3), and ANY child of C, (1,2,3). I would like one menu to popup when I click a child of B and a different one to popup if a child of C.

    Any Ideas

    Thanks

  2. #2

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45

    Here is my code so far

    I have managed to get this code so far:

    Code:
    public void mouseReleased(MouseEvent e)  {
                  //Gets info about tree
                  //Row number
                  int curRow = tree.getClosestRowForLocation(e.getX(),e.getY());
                  //Path
                  TreePath curTP = tree.getPathForRow(curRow);
                  //Get Node
                  DefaultMutableTreeNode curTN = (DefaultMutableTreeNode)curTP.getLastPathComponent();
                  //Get info for curTN and place in node
                  //DefaultMutableTreeNode node = (DefaultMutableTreeNode) curTN.getUserObject();
    
                  if (e.isPopupTrigger()) {
                     if (curTN.getParent().toString() == "A") {
      *                  Popup1.show(e.getComponent(), e.getX(), e.getY());
                     } else if (curTN.getParent().toString() == "B") {
      *                 Popup2.show(e.getComponent(), e.getX(), e.getY());
                     }
                  }
           }
    It causes a NullPointerException where the * are

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width