Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

Problem with JPopupMenu (I think...)

Thread view: 
blue - 14 Jan 2005 15:45 GMT
Brief overview:

I have a JTree within an applet.
I have a MouseListener on the JTree to trap a right mouse click and display
a JPopupMenu
...public void mousePressed(MouseEvent e)
        {
        if (e.isMetaDown())
           {
           showPopupMenu( e );
           return;
           }
        }

Problem:

We've encountered a problem (inconsistent), where a user will right click on
a "new" node on the tree, and the browser just hangs.  The only way to close
the browser is with task manager (I'm running WinXP, IE 6, jdk 1.4.2_04).

The showPopupMenu method is called:
public void showPopupMenu(MouseEvent mouse_event)
     {
     try
        {
        // get root node from tree model
        SpiderClientNode root_node =
(SpiderClientNode)tree_model.getRoot();
        // get the path from the mouse event object (where the user
clicked)
        TreePath mouse_click_path = getPathForLocation(mouse_event.getX(),
mouse_event.getY());
        // if mouse click path is null, do nothing
        if (mouse_click_path != null)
           {
           System.out.println("have mouse click path, now retrieving the
node at that path");
           // get SpiderClientNode from path
           SpiderClientNode mouse_click_node =
(SpiderClientNode)mouse_click_path.getLastPathComponent();
           // if node is null, do nothing
           if (mouse_click_node != null)
              {
              System.out.println("user clicked on node with product id: " +
mouse_click_node.getProductId());
              // get currently selected path
              TreePath selected_path = getSelectionPath();
              // get selected node from path
              SpiderClientNode selected_node =
(SpiderClientNode)selected_path.getLastPathComponent();
              // if selected node is different than the mouse click node,
set new selection path
              if (selected_node != null && selected_node !=
mouse_click_node)
                 {
                 System.out.println("selected node is different than the
mouse click node, setting new selection path");
                 // call method to set global variable for new path
                 setSelectionPath(mouse_click_path);
                 }
              // if mouse click node is not the root, display the popup
menu
              if (mouse_click_node != root_node)
                 {
                 System.out.println("mouse click node != root, showing
menu");
                 // instantiate popup menu
                 System.out.println("creating new popup menu");
                 SpiderTreeRTPopupMenu popup = new
SpiderTreeRTPopupMenu(parent_applet,mouse_click_node);
                 System.out.println("new menu created, display to user at
location X: " + mouse_event.getX() + " and Y: " + mouse_event.getY());
                 // show the menu at mouse click location
                 popup.show( mouse_event.getComponent(),
mouse_event.getX(), mouse_event.getY() );
                 System.out.println("menu should now be displayed");
                 }
              }
           else
              {
              System.out.println("user did not right click on a node in the
tree");
              }
           }
        else
           {
           System.out.println("mouse click path is null");
           }
        }
     catch (Exception e)
        {
        System.out.println("SpiderTreeRT::showPopupMenu(MouseEvent)::Unable
to show popup");
        e.printStackTrace();
        }
     }

I get all System.out's up until the popup.show method is called, then the
browser hangs.

Has anyone encountered such a problem?  Any input would be greatly
appreciated.

Thank you,
Frank
Andrew Thompson - 14 Jan 2005 22:58 GMT
> I have a JTree within an applet.

URL?

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

blue - 19 Jan 2005 13:48 GMT
Sorry,

Intranet only....

Frank

>> I have a JTree within an applet.
>
> URL?
Andrew Thompson - 20 Jan 2005 08:59 GMT
> Intranet only....

Why?  Is it secret?

If there is some compelling reason your applet cannot be shown
to the public, create an SSCCE[1] instead, and please note the
comments on line length.

[1] <http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

blue - 20 Jan 2005 15:06 GMT
When dealing with customer data, yes, it becomes "secret". I've set up a
test product which you can access from:

http://elogia-salesdemos.net/cse35/cse

Login with config/config

Select "RACK" under "- Product Configuration" in the "Enterprise Tools"
section on the left.

Once the applet loads, you will see a configuration tree on the left hand
side. A right click on any node other than the root will (should) display
the popup menu with information about that node. Sometimes the menu will
show, other times, the browser will just lock up.

Thanks for you time.  I've also tried changing my code so that no components
are instantiated in the listener events, this didn't help either.

Frank

>> Intranet only....
>
[quoted text clipped - 5 lines]
>
> [1] <http://www.physci.org/codes/sscce.jsp>
Andrew Thompson - 21 Jan 2005 09:10 GMT
Please refrain from top-posting Frank, I find it most confusing.
<http://www.physci.org/codes/javafaq.jsp#netiquette>

See further comments 'in-line with trimming'

>>> Intranet only....
..
>> ..create an SSCCE[1]
..
>> [1] <http://www.physci.org/codes/sscce.jsp>

> When dealing with customer data, yes, it becomes "secret".

Just a point, but since I will be referencing the above-linked
article again, I will point out that the SSCCE document advises
you to replace D/B and I/O related data structures with dummy
information (hard coded if necessary).

>..I've set up a
> test product which you can access from:
>
> http://elogia-salesdemos.net/cse35/cse

..Goood.

> Login with config/config

Ah, now..  Please read the SSCCE document.  This is a problem with
a *Tooltip* fer'chrissake [ ;-) ], there is no 'login' required to
replicate that, is there?

BTW - I should point out that some clever person may happen
along who can either guess, or spot, the problem.  But if that does
not happen, an SSCCE is the best way to solve the problem.

I suggest you go off and read the SSCCE document carefully and
consider what it says (there is more to it than first appearances
might suggest), then consider whether an SSCCE might be the way
to resolve this technical problem.  ...

[ My apologies if you have already read that document, but I
hoped it would make clear that a 'login' should be stripped
from the applet before asking people for help on the code. ]

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

blue - 28 Jan 2005 15:56 GMT
Just an FYI:

The problem turned out to be a conflict between showing the popup menu and
spawning an action thread on node selection.  If I simply run the method
calls in the change listener without threading them, all is well.

Thank you for all of your input.
Frank
Andrew Thompson - 29 Jan 2005 11:57 GMT
> The problem turned out to be a conflict between showing the popup menu and
> spawning an action thread on node selection.  

Thanks for reporting the problem resolution, and it's solution.

>..If I simply run the method
> calls in the change listener without threading them, all is well.

Excellent stuff, glad you sorted it.

> Thank you for all of your input.

You're welcome, always happy to help someone find their own solution.  ;-)

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.