Allow right-click selection in a JTree

Hi everybody! How are today? Fine? I hope so.
I've got a little question about JTrees: i want to put a right-click popup menu on my JTree, which may not be the same depending on which node of the tree is selected.
My problem is that i must do a left click selection of the node before doing the right click in order that this one may be effective and correct (i.e the correct popup menu appears).
So, i want to allow the right click selection in my JTree to select the node and to perform the action linked to the Popup menu.
I will be very thankfull if someone could help me :)

Sorry to post twice, but just thought i'd post the code to show you what I mean (forgive me not making this entirely generic):
///// Some "global" variables:
     private JPopupMenu               stPopupMenu;
     private TreePath               stPath;
     private String                    stPathComponent;
     private int                         stCount;
     private Object                    selectedNode;
///// Attaching the listeners:
symbolTreeDisplay.addTreeSelectionListener(stHandler);
symbolTreeDisplay.addMouseListener(stHandler);
//// The event listener class:
     private class SymbolTreeHandler extends MouseAdapter implements
               TreeSelectionListener
          public void mouseClicked(java.awt.event.MouseEvent event)
               try
                    if (event.getModifiers() == event.BUTTON3_MASK)
                    {//right button click on mouse
                         stPopupMenu = new JPopupMenu();
                         // add your logic here, based on selectedNode to add items to the menu
                         stPopupMenu.show(symbolTreeDisplay, event.getX(), event
                                   .getY());
               catch (Exception e)
          public void valueChanged(TreeSelectionEvent aTreeEvent)
               try
                    stPath = aTreeEvent.getPath();
                    stCount = stPath.getPathCount();
                    selectedNode = stPath.getPathComponent(stCount - 1);
               catch (Exception e)
     }

Similar Messages

  • Right click select node in tree (for a standalone Air app)?

    For the sake of userfriendliness (in regard to a context menu) I wold like to "move" the selected node in a tree to the node that currently has the focus when right clicking it - like how the context menu access in windows file explorer works (focus and selected item are always the same  when right clicking).
    In worst case scenario I would like to disable a created context menu if the selected node and the node that currently has the focus are not the same).
    Now users can get confused when right clicking to access my context menu, in the tree structure, if the selected node and the node they are currently hovering over (and thus are in focus) are different.
    I was thinking of finding which node currently has the focus and then making that node the selected node - but I cant get it to work:-).
    Please, help a beginner.

    Hi,
    Duplicate thread of
    http://swforum.sun.com/jive/thread.jspa?threadID=64518
    MJ

  • Hiding transparent Flash layer to allow right clicks

    Hi all
    Working
    example!
    I have created a page in Dreamweaver with transparent flash
    content. My problem is when I position my mouse over the
    transparent area to copy text or click a link nothing happens, and
    when I right click over the transparent area I get the regular
    Flash menu!
    I have placed a my swf Menu in my HTML page using the Draw AP
    Div tool.
    thanks in advance
    javono
    http://www.javono.com

    yeah, ZINC is a great app and allows you to get the
    functionality of a desktop application. Another way to possilby do
    it is by creating a AIR application in flash. I don't know that
    much about AIR as of yet, but that could be another thing to look
    into, an it doesn't require a 3rd party app. You may also be able
    to do it using a BAT file executed through the FSCommand in
    flash.

  • Right click selection issue

    I am using HP Laptop with window 8.1.
    The right click button on the keyboard is not available so till the time I was using mouse for the right click.
    Now I install Hotkeys software & configure right Alt button of the keyboard as a right click button.
    It is working fine means whenever I clicked on the right Alt it is working as a right click, this is helpful in excel specially.
    But after this I am facing a new issue, this issue is when I using excel or word.
    When I move the cursor & select any cell with the mouse & then click on right alt it work properly.
    But after the selection from the mouse if I change the location by using arrow keys of the keyboard the location get changed but after changing the selection when I click on right Alt button the right click options open for the cell which was selected by
    the mouse.
    Hope it is clear.
    Example- If I select A5 location in excel by mouse & then goes right with keyboard right click on C5 location, the selection goes to the desired location, but if now I click on right Alt to open the options the cursor automatically opened the properties
    of A5 instead of C5.
    Here I clicked by mouse on A5 & moves to C5 by keyboard.
    Please help.
    This is  not an issue of scroll lock.

    I am using HP Laptop with window 8.1.
    The right click button on the keyboard is not available so till the time I was using mouse for the right click.
    Now I install Hotkeys software & configure right Alt button of the keyboard as a right click button.
    It is working fine means whenever I clicked on the right Alt it is working as a right click, this is helpful in excel specially.
    But after this I am facing a new issue, this issue is when I using excel or word.
    When I move the cursor & select any cell with the mouse & then click on right alt it work properly.
    But after the selection from the mouse if I change the location by using arrow keys of the keyboard the location get changed but after changing the selection when I click on right Alt button the right click options open for the cell which was selected by
    the mouse.
    Hope it is clear.
    Example- If I select A5 location in excel by mouse & then goes right with keyboard right click on C5 location, the selection goes to the desired location, but if now I click on right Alt to open the options the cursor automatically opened the properties
    of A5 instead of C5.
    Here I clicked by mouse on A5 & moves to C5 by keyboard.
    Please help.
    This is  not an issue of scroll lock.

  • Bug in right click selection in reports

    Build 22.71, on Linux and Windows.
    When I go to, for example, the sessions report, and right click on a row which I want to invoke a trace session command on, the whole column where I right clicked get selected, so it does not correctly indicate to the user which session will have trace enabled on.

    Add mouselistener:
    MouseListener ml = new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
             if (SwingUtilities.isRightMouseButton(e)) {
               doSomething();
          }//mousePressed
          public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
              doSometing();
          }//mouseReleased
        };//mouseListener
        myList.addMouseListener(ml);

  • Stopping right click selecting tab in JTabbedPane

    Hello all,
    This may be a really simple thing + I'm probably being thick, but is there a way to prevent a right click changing the selected tab on a JTabbedPane.
    I tried consuming the MouseEvent, but that didn't seem to work. Couldn't find an answer anywhere else in the forums & couldn't see anything in the JavaDoc that looked as if it would help.
    Answers on a postcard please......
    RT

    You might be able to extend JTabbedPane and override setSelectedIndex().
    I had to do this to work around a focus issue I had.
      This class extends JTabbedPane to correct a problem where it doesn't
      request focus when clicked on.
    import java.awt.*;
    import javax.swing.*;
    public class MyJTabbedPane extends JTabbedPane {
      public void setSelectedIndex(int index) {
        Component comp = KeyboardFocusManager.
            getCurrentKeyboardFocusManager().getFocusOwner();
        //  if  no tabs are selected
        // -OR- the current focus owner is me
        // -OR- I request focus from another component and get it
        // then proceed with the tab switch
        boolean noTabSelected = getSelectedIndex()==-1;
        boolean hasFocus = requestFocus(false);
        boolean compIsMe = comp==this;
        if(noTabSelected || hasFocus || compIsMe) {
          super.setSelectedIndex(index);
    }

  • Right click select all?

    Hi, Is there an easy way to add a select all command to the contextual menu when you right click/ctrl click in the finder?
    I've tried some v complex apps & had no success.. Thanks.

    Welcome to Apple Discussions.
    There is a free utility called, OnMyCommand which can do this...
    http://www.macupdate.com/info.php/id/9283/onmycommand
    There's also the ⌘ -a keystroke.
    -mj

  • Right clicking selection gives nothing

    So to make this short, I can use the pen tool to create a shape, then by right clicking it I can decide what I want to do with it. When I click "Make selection" I've selected the shape, but when I right click it again in order to find out what I want to do with that shape, it doesn't let me do anything. Everything grayed out. Normally I'd have the option to copy to layer or copy to cut but nothing.
    Looks like this

    I can see that you have made a shape with the Pen tool.  You have right clicked and cosen Selection, but you must have specified a high Feather value because the selection only covers a small part of the shape, (the matching ants indicate 50% opacity). 
    From there, you would take other routes to achieve what you mention.  Ctrl j would copt the selection to a new layer, for instance, but that layer will have a heavily feathered outline.   You should still have some options if you right click again, but useful as right clicking can be, it doesn't cover everything.

  • Right-click/select on trackpad not working

    Hi
    Basically the "right click" option on my trackpad has stopped working, I can't highlight sections of text or images, can't click and drag any items and can't resize windows or images. I'm going crazy does anyone know what's wrong? I called Apple and they didn't really help with anything, I've reset my preferences to default but no luck!
    I can scroll with two/three/four fingers fine it's just when I want to click with two that nothing happens.
    Any help would be greatly appreciated!
    Alyssa

    01/04/14 Update:  I've updated all SW (BIOS, UltraNav Driver and Utility, latest Win7 updates) but right button still won't work.  Ran the PC Doctor diags for the UltraNav and it shows the right button highlighted constantly (as opposed to it blinking on/off when button is processed like the the left button does).

  • Safari not allowing right click?

    I have a fresh install of 10.4.7, whenever I start Safari, and make a spelling error, I right-click and safari gives me a beach ball of death. I also get the error whenever I try to create a new tab.
    This sometimes goes away after visiting another web site, but I have to force quit Safari to obtain functionality again...
    I have removed all preferences except the bookmarks, and it still happens. Any help would be appreciated on why this is going on.

    What was your original OS? If it was under 10.4.0, PLEASE TELL ME! Otherwise try updating Safari in Software Update.

  • Right click selection

    Hello,
    can i make selection in JList by right mouse click?
    thanks

    you can test (MouseEvent)e.getModifiers into "BUTTON1_MASK", "BUTTON2_MASK" and "BUTTON3_MASK"

  • How to get a pop-up menu on right click of JTree?

    hi
    My application consists of a JTree.I am having a 2 root nodes each one have some child nodes.in the first root node what i want is on right click of child node i have to display one option that is enabled and on the second root node what i want is on right click of child node i have to display one option that is disabled..
    how to do that
    thanks for your reply in advance,

    When you are creating your nodes, do node.setUserObject(objectName);
    and on right click, do something like this
    if (e.isPopupTrigger() == true) {
             selPath = tree.getPathForLocation(e.getX(), e.getY());
          try {
             // If Right Click, Select the Node
             Object[] selectedPath = selPath.getPath();
             DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectedPath[selectedPath.length - 1];
             try {
                dataObject = (MyObject) selectedNode.getUserObject(); // Set the Data Object
             } catch (ClassCastException ex) {
                                      ex.printStackTrace();
             // Check for the right click on Framework Node
             if (dataObject.getClass().isInstance(new MyObject()) == true) {
                // Disable the pop-up menu
    ....

  • Out of the blue, unable to open Word attachment in Mail with double click. Have to Right click, open with, select Microsoft Word. Am running Snow Leopard and Microsoft Office for Mac 08. Cheers

    Out of the blue, am unable to open Word attachments in Mail with the usual double click. (Get a longwinded error message)
    Need to right click, select open with, and select Microsoft Word. Have been using Microsoft Office for Mac 08 for years.
    I have reinstalled the Office software. A couple of tech people have been unable to fix it. Any suggestion?? debsuemy

    Please re-post in the Office for Mac Product Forums .

  • Right-click multiple JTable rows at once?

    Hi everyone,
    Haven't posted for a while but I've been trawling through Google and these forums looking for anyone who has implemented a JTable that allows the user to right-click multiple rows after selecting the multiple rows with a left-click. Currently the JTable allows multiple rows to be selected (MULTIPLE_SELECTION policy enabled) yet when you right-click on any of the highlighted rows it only right-clicks on the one out of the group you happened to click on and deselects all the other previously selected rows. Does anyone know of a way of enabling the right-click of multiple items (new listener or just a simple parameter change?)
    Any help would be much appreciated.

    I just have a mouse listener which, on a right-click, selects the row if it's not currently selected and does nothing if the row is already selected; then pops up the menu.

  • Acrobat 11 Pro - problem with right-click "Convert to Adobe PDF" output folder

    I'm migrating from one machine running Windows XP Pro with Acrobat 8 Pro to Windows 7 Pro with Acrobat 11 Pro.
    On the XP machine, when I right-click on a document and select "convert to Adobe PDF" the process works just fine - it always outputs the file to the target destination I have set in the Adobe PDF printer definition.
    On the Windows 7 Pro/Acrobat 11 Pro machine, the exact same settings are ignored: the PDF will always end up in the same folder as the source file.
    Both the source folder and the destination folder are on one of my office's networked drives.
    Under the Printing Preferences, I have the output folder address set the same on both machines, so it *should* go to the right location on the new machine.
    Oddly enough, on the Acrobat 11 Pro machine, if I select Adobe PDF as the default printer and do a test print, it *does* print to the correct folder!
    This has got me stumped!
    Thoughts?
    (update from later in the day)
    If Adobe PDF is selected as the default printer, I *can* select a bunch of documents, right-click, select "print", and Word will open up, and they'll print to the correct target folder.
    So, it's "just" the right-click "Convert to Adobe PDF" that doesn't work correctly.

    The reinstall is typically the last ditch effort to do. The first step is Help>Repair and Help>Updates. As far as Office 2013, the PDF Maker of AA X is not compatible and you can only print. In your list of errors it showed a problem with AcroTray.exe. As a first step, go to the print and select print-to-file. The file will be a PS file (maybe with a PRN extension). Once the printer if finished, open the file in Distiller to complete the process. If that is successful, then the problem is with AcroTray. Check your running tasks to be sure AcroTray is indeed running. If not, that is likely the problem. If it is, then restart it (it is located in the Acrobat folder). AcroTray provides the interface between the PS creation and Distiller to automate the process of creating the PDF.

Maybe you are looking for

  • Function module MD_SALES_ORDER_STATUS_REPORT

    Hello, When we execute the order report for production order or sales order, the function module that is used is MD_SALES_ORDER_STATUS_REPORT but what about Planned independent requirements ? Is it the same function module or is it different please?

  • Adding a print button on a slide?

    Hi I have had a request to add a print icon button on each slide of the programme I am creating. They want it possible for the user to print any of the slides if deemed they wish. Is this option available in Captivate 5.5? If so how do I do this? Tha

  • I CAN'T SEE MOBILE IMAGE IN MY COMPUTER WHEN CONNE...

    When I had Purchased my Nokia 5233,and when i used to connect it in PC SUITE mode....it Used to show NOKIA 5233's PHOTO as a MOBILE Device connected...... But nOw A Days....i mean From 2months or SO, i Just See my Phone as a MEDIA PLAYER CONNECTED Th

  • Migrating 10g ADF application for OC4J to 11g application for Weblogic

    Hi, I'm trying to migrate a 10g ADF application deployed in OC4J to 11g using the migration tool of JDeveloper. After some changes in code to adapt to the new api i have an error in libraries while trying to deploy in embeded weblogic. <30 Ιουν 2010

  • SQL Replication to mobile clients

    Hi all, I've been messing around with SQL Server replication here the last few days and I have a couple questions...  Background information is that this is mostly in a test environment so I can change things pretty free and easy. 1. my setup would b