Rename a Jtree node directly & Popup Menu

Pls assist with codes to rename a Jree node directly without using a dialog box or optionpane. I tried
tree.startEditingAtPath(/* path of selected node*/);
to go to edit mode and it does not work.
II. Is it possible to attach different popmenu to the root, separate from the parent and child? Pls assist with code as the popupmenu i use at the moment shows up on the nodes(root, parent, leaf).
I have benefiited greatly from questions asked and answers proferred at this forum and I use this opportunity to thank everyone greatly as I have migrated to Java based on all the materials sourced on the net.
[email protected]

public class AutomatedTreeMouseHandler extends MouseAdapter {
     public void mousePressed(MouseEvent e) {
          JTree tree = (JTree) (e.getSource());
          int x = e.getX();
          int y = e.getY();
          TreePath path = tree.getPathForLocation(x, y);
          if (path != null) {
               // generate your popup here
Dennis,
are you saying that i have to define the popmenu for each category of node in the mouseadapter and att'd these to the tree depending on whether root, leaf or whatever type of node is selected?
I will try this and revert.
I can not make anything out of the reference giving with regard to renaming a node in edit mode.
Pls provide more explanation and sample code, if necessary.
Thanks a million.

Similar Messages

  • Xml in JTree: how to not collpase JTree node, when renaming XML Node.

    Hi.
    I'm writing some kind of XML editor. I want to view my XML document in JTree and make user able to edit contents of XML. I made my own TreeModel for JTree, which straight accesses XML DOM, produced by Xerces. Using DOM Events, I made good-looking JTree updates without collapsing JTree on inserting or removing XML nodes.
    But there is a problem. I need to produce to user some method of renaming nodes. As I know, there is no way to rename node in w3c DOM. So I create new one with new name and copy all children and attributes to it. But in this way I got a new object of XML Node instead of renamed one. And I need to initiate rebuilding (treeStructureChanged event) of JTree structure. Renamed node collapses. If I use treeNodesChanged event (no rebuilding, just changes string view of JTree node), then when I try to operate with renamed node again, exception will be throwed.
    Is there some way to rename nodes in my program without collpasing JTree?
    I'am new to Java. Maybe there is a method in Xerces DOM implementation to rename nodes without recreating?
    Thanks in advance.

    I assume that "rename" means to change the element name? Anyway your question seems to be "When I add a node to a JTree, how do I make sure it is expanded?" This is completely concerned with Swing, so it might have been better to post it in the Swing forum, but if it were me I would do this:
    1. Copy the XML document into a JTree.
    2. Allow the user to edit the document. Don't attempt to keep an XML document or DOM synchronized with the contents of the JTree.
    3. On request of the user, copy the JTree back to a new XML document.
    This way you can "rename" things to the user's heart's content without having the problem you described.

  • Icon CHANGE in Node Renaming  for JTree

    HI all ,
    In JTree, V can rename a DefaultMutableTreeNode , by pressing F2 or triple click .
    By using the DefaultTreeCellRenderer ,
    I applied icons also by -- tree.setCellRenderer(myCellRenderer);
    But at the time of renaming , or when v press F2 ,
    the icon is changed to default settings ( leafIcon / openIcon / closedIcon ).
    How can I apply other Icons to nodes at the time of node renaming ?
    Please help ..
    Thanks

    MyTreeCellRenderer treeCellRenderer = new MyTreeCellRenderer();
    DefaultTreeCellEditor treeCellEditor = new MyTreeCellEditor(tree, treeCellRenderer);;
    MyTreeCellEditorListener cellEditorListener = new MyTreeCellEditorListener();
    treeModel = new DefaultTreeModel (rootNode);
    tree = new JTree(treeModel);
    treeCellEditor.addCellEditorListener(cellEditorListener);
    tree.setCellEditor(treeCellEditor);
    tree.setCellRenderer(treeCellRenderer);
    I am renaming the leaf nodes and MyTreeCellRenderer class override the method
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
    and set a different icon to the leaf nodes.
    And when i am renaming a leaf node , the default ( leafIcon ) icon will come only to the renaming node at the time of renaming . When i hit the enter key . the default leafIcon will disappear and my customised icon will come .........
    My question is that at the time of renaming ........ How v can getback the customised icon ?
    thanks

  • Creating Context Menu for JTree Node

    Hi to all,
    I need to create Context Menu, when i right click on any Tree Node.
    Context Menu should contain selected node information.
    if you click on one tree node named as "AAAA"
    Context Menu Format is as follows
    AAAA
    Create New
    Delete
    If any one knows, please help me

    Here is something for you to start
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=538065
    Denis Krukovsky
    http://dotuseful.sourceforge.net/

  • PopupMenu on Jtree nodes Please [b]Help me][/b]

    how can I set my JpopupMenu to work on Jtree nodes and not on the tree?

    how can I set my JpopupMenu to work on Jtree nodes
    and not on the tree?Could you elaborate? Are you asking that popup events are ignored if the mouse click is not actually on the rendered area of a node or are you asking something else?

  • How to create a splitted button with a popup menu?

    Hi,
    i am trying to build a button which can be clicked and an action is called (a normal button) and an addion to that basic function: there is on the right side of the button a seperated area with an arrow. If this arrow is clicked a popup menu becomes visible and you can choose a special action. This type of buttons (i don't know the name) can be seen by example in Eclipse or the Windows Media Player 11 or in Windows Vista).
    Here is an example image about what i mean: http://s2.imgimg.de/uploads/button56b4941cpng.png
    Can you tell me how to create a button with this possabilities?
    Please help me,
    greetings from germany,
    picard90

    hii,
    if you are want completed to define the Popup, then you have to define accesible areas,
    1/ create Popup (example from void)
    public void createPopupMenu() {
    JPopupMenu popup = new JPopupMenu();
    popup.addSeparator();
    ShowsManFxMenuItem = new JMenuItem("Show Details");
    ShowsManFxMenuItem.addActionListener((new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    //..some actions
    validate();
    repaint();
    popup.add(ShowsManFxMenuItem);
    MouseListener popupListener = new PopupListener(popup);
    //here is your listener directly to prepared object "yourButton"
    yourButton.addMouseListener(popupListener);
    2/ create POpupListener (example is class)
    class PopupListener extends MouseAdapter {
    JPopupMenu popup;
    PopupListener(JPopupMenu popupMenu) {
    popup = popupMenu;
    @Override
    public void mousePressed(MouseEvent e) {
    maybeShowPopup(e);
    @Override
    public void mouseReleased(MouseEvent e) {
    maybeShowPopup(e);
    //only in this block you can restrict anything with popup items (test anything and then to display all, only one, parts of them)
    private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
    popup.show(e.getComponent(), e.getX(), e.getY());
    //these parts you can ingnore, but can covered extended events from popup
    public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    protected String getClassName(Object o) {// Returns just the class name -- no package info.
    String classString = o.getClass().getName();
    int dotIndex = classString.lastIndexOf(".");
    return classString.substring(dotIndex + 1);
    3/ I removed all my addition
    ... kopik

  • Mouse right click button, popup menu, PC frozen

    Hello all,
    It has been while I've been noticing this problem.
    Almost every time I click with the right mouse button on an email from the list of emails or a word inside the content of an email to see which words are suggested by the spell checker, the usual popup menu appear but immediately after
    my PC gets frozen. I need to restart it.
    I don't think TB causes that crash, but something indirectly related.
    How can I debug this? (I'm software developer)
    Thank you so much.
    Roberto

    Update1:
    I put my attention only in the main TB menu.
    I disabled the TB extensions (only Lighting and EnigMail) and tried again to play with the main TB menu.
    With this new TB GUI, you don't see directly the main menu. I usually click the ALT key and the main menu will be displayed. After that I play with it a bit. That means, I clicked on on Tools or File or View etc items and just moved the mouse cursor over the popup menu, without clicking on a specific submenu item. After a while, some seconds, the PC gets frozen and I need to restard the PC.
    I started TB in safe mode also (-safe-mode). In this mode the main menu appears always so I don't need to click on the ALT key.
    I repeat the same steps of moving the mouse cursor of popup main menu items. Up to now, all is normal, without crashing or freezing.
    PC: Win7 (full updated), x64, TB last version.
    Any idea how can I debug this problem?
    Thanks

  • Developing a Sorted Popup Menu

    Hello Folks;
    How would I go about developing / scripting a sorted popup menu for Numbers in iWork 09?
    Thank you,
    vic

    Hi Vic,
    Welcome to Apple Discussions and the Numbers '09 forum.
    The bad news is that popup menus in Numbers aren't sortable, except by heavy handed editing. You can add items—but only to the bottom of the list, you can delete items—from anywhere in the list, and you can rename items.
    You can use Fill down or Fill right to copy a popup menu into a range of cells, but if these are edited popups replacing older versions, the previously set values will be replaced by the value set for the original being pasted in.
    For some flexibility, you might want to use a technique involving a Slider, a LOOKUP table and the VLOOKUP function. Jerrold Green wrote about it and provided some examples in discussion of Working with Pop-up menus in this forum back in April. The link will take you to that discussion.
    Regards,
    Barry

  • Table Popup menu of NW 2004s

    The latest SDN newsletter mentions that the new feature Popup menu is available for Table UI. However, no blog/tutorial talks about how to create it for a table. Searching the API doc / help.sap.com still gives no clue on table's popup menu.
    Please help on:
    1. How to create a popup menu belongs to a table?
    2. How the popup menu's item be related to the row/column/cell that the right-click happens?
    Thanks in advance!

    Tony,
    1.) Create a table and bind its dataSource property to the suitabel node.
    2.) Insert a column with table cell editor as "TextView" and "CellVariant" as "TablePopinToggleCell".
    3.) Create all the other columns (with suitable table cell editors / cell variants as per your need), with proper data binding.
    4.) Right click the table and choose "Insert Popin". Select the popin and choose "Insert Content" and select the corresponding UI element, say TextView.
    5.) Bind the "text" property of the TextView to the suitable attribute which you wanted to display in the popin.
    6.) Similarly you may insert a "TextBar" (right click TablePopin and choose "Insert TextBar") and bind it to the suitable attribute.
    Thatz it. Table popin is ready. ;-). You may follow the same steps to insert a popin for a column as well. (Select a column and choose "Insert Popin").
    (<b>Note:</b>
    By inserting cell variant TablePopinToggleCell into the first column of the table, you can implement opening and closing of a TablePopin. When the user clicks the TablePopinToggleButton, the TablePopin opens below the row; when the user clicks again, it closes.
    <b>End of Note:</b>)
    <b>Sorry.Ignore my post and follow maksim's solution if you want POPUP rather than POPIN.
    </b>
    ~ Bala
    Message was edited by: Bala

  • Please help with JTree Node Duplication

    Iam building a JTree which should not allow node duplication.
    1.)First i construct a ArrayList which stores all the previous nodes.
    treeNodeNames=new ArrayList();
    2.)i call the method
              readTreeNodeNames((DefaultMutableTreeNode)dtm.getRoot());
    3.)The method readTreeNodeNames is
    public void readTreeNodeNames(DefaultMutableTreeNode node) {
              if(node.toString().toLowerCase().length()!=0) {
              treeNodeNames.add(node.toString().toLowerCase());
              for(Enumeration en=node.children();en.hasMoreElements();) {
                   DefaultMutableTreeNode childNode=(DefaultMutableTreeNode)en.nextElement();      
                   if(childNode.toString().toLowerCase().length()!=0) {
                        treeNodeNames.add(childNode.toString().toLowerCase());
                   if(!childNode.isLeaf()) {
                        readTreeNodeNames(childNode);
    4.)i have four menu when right click a node add,modify,add subnode,delete.
    node duplication fails in my case.when should i call this method?should i call while doing every above mentioned operations or in TreeModelEvent implementations?
    i have mailed this problem already two times.but no one has not replied.Kinldy consider it and give me a solution.Or anyone having code for JTree Node duplication please send me to [email protected]

    Hi all,
    Any ideas to overcome this problem.?
    Thanks,
    Krish

  • Problem with Pre-Popup-Menu in Hierarchical Tree

    Hi,
    In Forms 10g I have made an application with an Hierarchical Tree. All works well, except the use of the Pre-Popup-Menu trigger.
    In that trigger when I read the values of Node_Label and Node_Value I get the values of the previous selected node, not the values of the node on which I issue the right mouse click. So, it seems that by clicking the node I need is not selected.
    Does anyone have any clues to solve this problem?
    Thanks in advance.

    Right clicking does not change the current selection. The tree has no way to report what node was right clicked. Only work around is to left click the node you wish then right click it.
    --pat                                                                                                                                                                                                                                                                                                                                                                                                       

  • Optimizing using static Popup Menu - How to do listeners?

    Ok, I just did a little profile of my application, and realized a bit of a problem. I have a large number of items subclassing JLabel. Each has a popup menu, with, say, 5 JMenuItems. This leads to a whole lot of JMenuItems, even though they are all the same. So my first thought was to make a single, static JPopupMenu.
    Now the place where differentiated behavior should occur is in the listener that listens to the menu items. The data a listener needs to display when an event occurs is needed is specific to the instance of the label.
    Basically, what I'd like to know is, is there a good way to cut down on instances of the menu items while keeping the necessary functionality.
    Let me know any ideas you have, or get me to clarify anything, and I'll try.

    You are right, JLabel also inherits from Container..maybe i should look into the hierachy before writing such things...
    first: i reworked the code a bit so now it should work
    second: is the popupmenu the only source which invokes actionevents?
    then you could remember the eventsource when the popupmenu is invoked (in mouseListener) and use it when a actionevent occurs (see attribute myEventSource)
    btw. you must register the popupmenu with the overseer too because it is a container "outside" your panel (no direct child)
    <code>
    public class MyOverseer implements ActionListener, MouseListener {
    JLabel myEventSource = null;
    public void registerThis (Component comp) {
    //recurse subcomponents
    if (comp instanceof Container) {
    Component[] childs = ((Container) comp).getComponents();
    for (int i=0; i<childs.length; i++)
    registerThis(childs);
    //Alt1: cast specifically
    if (comp instanceof JLabel) {
    ((JLabel)comp).addMouseListener(this);
    //Alt2: using reflection
    Class thisClass = this.getClass();
    Class[] implementedInterfaces = thisClass.getInterfaces();
    for (int i=0; i<implementedInterfaces.length; i++) {
    Class aInterface = implementedInterfaces[i];
    String interfaceName = aInterface.getName();
    if (interfaceName.endsWith("Listener")) {
    //Name of the addXYZListener-Method
    String addMethodName = "add"+interfaceName;
    try {
    //get class of current component
    Class componentsClass = comp.getClass();
    //get the add-method
    Method addMethod = componentsClass.getMethod(addMethodName, new Class[] {aInterface});
    //invoke the add-method on the current comp and pass THIS as argument
    addMethod.invoke(comp, new Object[] {this});
    catch (NoSuchMethodException nsme) {} //can't add this Listner
    catch (InvocationTargetException ite) {
    ite.printStackTrace();
    catch (IllegalAccessException iae) {
    iae.printStackTrace();
    * MouseListener methods
    public void mousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
    if (e.getSource() instanceof JLabel) {
    myEventSource = (JLabel) e.getSource();
    //Show popup
    else {
    //whatever
    public void mouseClicked(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    * ActionListener methods
    public void actionPerformed (ActionEvent e) {
    if (myEventSource!=null) {
    //do something
    //after that
    myEventSource == null; //just as before
    </code>
    Thanks for the dukes ;-)
    Regards,
    rookie_no2

  • How to sort jTree Nodes

    Hi,
    I am interested in whats the easiest way to sort jTree Nodes alphabetically. Is there any Method to do this directly or may i use something like quicksort?
    Thanks for help
    Mirco

    Thanks Hamed,
    Well, I work in your code, and I post here.
      public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) {
                     for (int i =0; i<root.getChildCount()-1; i++) {
                              DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
                            String nt = node.getUserObject().toString();
                            for (int j=i+1;j<=root.getChildCount()-1;j++)
                                     DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) root.getChildAt(j);
                                        String np = prevNode.getUserObject().toString();
                                System.out.println(nt+" "+np);
                                if (nt.compareToIgnoreCase(np)>0) {
                                               root.insert(node, j);
                                             root.insert(prevNode, i);
                            if (node.getChildCount() > 0) {
                        node = sortTree(node);
                     return root;
        }and this code I used after include in jtree
      public  void jTreeSortingBegin()
              dn = (DefaultMutableTreeNode)treeModel.getRoot();
              treeModel.reload();
              dn = sortTree(dn);
              treeModel.reload(dn);
        }for exemple
      addObject(jTextField1.getText());
            jTreeSortingBegin();

  • Empty popup menu

    Hi,
    we implemented an excel-download function according blog "Creating a BSP Extension for Downloading a Table" (/people/thomas.jung3/blog/2004/09/02/creating-a-bsp-extension-for-downloading-a-table). This creates a menu-entry using the standard popup menu function.
    It worked fine but after several patches (SAP BASIS SPs ) we figured out, the the BSP now is showing an empty span without the menu-items in it (although the menu entries are in the HTML-Code).
    We think, that this is a problem with the called Java-Script method onclick="sapUrMapi_PopupTrigger_openMenu('EXCEL_INTERFACE__popupTrigger','EXCEL_INTERFACE__popupMenu',event);
    Do you have any experience at this or face the same problem?
    Thanks for help.
    Best regards
    Katrin

    I have some kind of workaround for my problem. I changed my Handler to search for all MParts matching my Part-ID. I check all Parts for there setup and possible update it. But when I decide I need a new Part, I clone the Part using the cloneElement-Method of the EModelService and activate it with the EPartService.
    With this method the popup menu also shows on the newly created Part.
    There is still a Problem, removing the second Plugin which contains the HandledItems for the Parts results in an error for the active part and a disabled popup menu for the other parts. I also don't known what will happen if I later add a new Plugin with new HandledItems.
    So still it would be nice if anyone can lead me to the right direction.

  • DW & FW8 Popup Menu Relative Positioning

    I can tell there's been a lot of discussion here about using,
    or not using, DW popup menus. Here's my situation: I'm successfully
    (really) using a popup menu on a left-justified site. We've now
    added a blog to the site. That blog page is centered. Of course,
    the popup doesn't line up properly like it does on the rest of the
    site. I'm told there's a way to position the menu relative to it's
    trigger, and not by xy coordinates in DW8. Can anyone verify that,
    and, if so, tell me how to do it?
    Thanks much,
    Jan

    > I'm successfully (really) using a popup
    > menu on a left-justified site.
    So you think. But do you know that your site will not be
    spidered if that's
    your only navigation? And do you know that the menu will
    break if you move
    or rename a linked file? And do you know that your menu
    doesn't work if js
    is disabled? And do you know that your menu is inaccessable?
    > Can anyone verify that
    It's possible to make the layers that are written dynamically
    by the pop-up
    menu code center, yes.
    > tell me how to do it?
    I am reluctant to encourage anyone to continue using these
    menus. But
    consider this -
    Change this -
    </head>
    to this -
    <style type="text/css">
    <!--
    body { text-align:center; color:#CCC; }
    #wrapper { text-align:left; width:720px; margin:0
    auto;position:relative; }
    -->
    </style>
    </head>
    change this -
    <body ...>
    to this -
    <body ...>
    <div id="wrapper">
    and this -
    </body>
    to this -
    </div><!-- /wrapper -->
    </body>
    and see if that helps.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "jknewlegend" <[email protected]> wrote in
    message
    news:e7pgo2$b4t$[email protected]..
    >I can tell there's been a lot of discussion here about
    using, or not using,
    >DW
    > popup menus. Here's my situation: I'm successfully
    (really) using a
    > popup
    > menu on a left-justified site. We've now added a blog to
    the site. That
    > blog
    > page is centered. Of course, the popup doesn't line up
    properly like it
    > does
    > on the rest of the site. I'm told there's a way to
    position the menu
    > relative
    > to it's trigger, and not by xy coordinates in DW8. Can
    anyone verify
    > that,
    > and, if so, tell me how to do it?
    >
    > Thanks much,
    > Jan
    >

Maybe you are looking for

  • Field in PCUI

    Hi, I have added a field to opportunity transaction through EEWB. I want to populate this field in PCUI and not in SAP GUI. So i have made Z_ class as a subclass of CL_CRM_BSP_AM_HEADFM_1o. In this i have redefined the READ method, and have called ma

  • FindSystemUser/driver locator error when starting the default server

    Getting the error when trying to start the default server. "findSystemUser: System user is not available from Credential Store." and "oracle.sdpinternal.messaging.TransportException: Cannot lookup store in Driver Locator." I am also unable to access

  • Using an own function in a select how can i set that the function run once?

    Hi Using an own function in a select how can i set that the function run once, not in every row? Please help me Thanks Viktor

  • Unable to open some forms

    I have installed Adobe reader.  I am able to open some forms from a particular website, but not others.  The one I need it a fillable online PDF form.  Why am I not able to open this form when I can open others in the same format from the same websit

  • ACR 5.2 Tutorials

    I've just installed CS4 update along with ACR 5.2 on my MacBook Pro,OSX 10.5.5. I am excited to get started making use of the new tools in ACR 5.2. I am fairly proficient and comfortable using CS3 and ACR 4.6. Can anyone recommend a good tutorial or