How to cut, copy and paste a tree node in JTree?????

Hi, Java GUI guru. Thank you for your help in advance.
I am working on a File Explorer project with JTree. There are cut, copy and paste item menus in my menu bar. I need three EventAction methods or classes to implements the three tasks. I tried to use Clipboard to copy and paste tree node. But I can not copy any tree node from my tree.
Are there any body has sample source code about cut, copy, and paste for tree? If possible, would you mind send me your sample source code to [email protected]
I would appreciate you very very much for your help!!!!
X.G.

Hi, Paul Clapham:
Thank you for your quick answer.
I store the node in a DefaultMutableTreeNode variable, and assign it to another DefaultMutableTreeNode variable. I set up two classes (CopyNode and PasteNode). Here they are as follows:
//CopyNode class
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class CopyNode implements ActionListener{
private TreeList jtree;
String treeNodeName;
TreePath currentSelection;
DefaultMutableTreeNode currentNode;
public CopyNode(TreeList t){
jtree = t;
public void actionPerformed(ActionEvent e){
currentSelection = jtree.tree.getSelectionPath();
if(currentSelection != null){
currentNode = (DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
treeNodeName = currentNode.toString();
//PasteNode class
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class PasteNode extends DefaultMutableTreeNode{
private TreeList jtree;
CopyNode copyNode;
public PasteNode(TreeList t){
jtree = t;
copyNode = new CopyNode(t);
public DefaultMutableTreeNode addObject(Object child){
DefaultMutableTreeNode parentNode = null;
TreePath parentPath = jtree.tree.getSelectionPath();
if(parentPath == null){
parentNode = jtree.root;
else{
parentNode = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
return addObject(parentNode, child, true);
public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible){
DefaultMutableTreeNode childNode = copyNode.currentNode;
if(parent == null){
parent = jtree.root;
jtree.treemodel.insertNodeInto(childNode, parent, parent.getChildCount());
if(shouldBeVisible){
jtree.tree.scrollPathToVisible(new TreePath(childNode.getPath()));
return childNode;
I used these two classes objects in "actionPerformed(ActionEvent e)" methods in my tree:
//invoke copyNode
copyItem = new JMenuItem("Copy");
copyItem.addActionListener(copyNode);
//invoke pasteNode
pasteItem = new JMenuItem("Paste");
pasteItem.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
pasteName.addObject(copyName.treeNodeName);
When I run the drive code, making a copy some node from my tree list, I got bunch of error messages.
Can you figour out what is wrong in my two classes? If you have sample code, would you mind mail me for reference.
Thank you very much in advance.
X.G.

Similar Messages

  • Cut, copy,and paste on nokia n97

    can someone please help me. I dont know how to cut, copy,and paste on my nokia n97
    6680,n70,n73,n80,n80ie,n82,n95,innov8,n85, n97, N8, lumia 920

    I had some difficulty locating this 3 line icon myself.
    Turns out that if you close the screen down and tap the input box on the web page you want to paste the text into, up pops an application (text entry I suppose, anyway it has a load of stuff, green tick top left, and then this magical 3 line icon, followed by what I assume is the predictive text input status, a keyboard icon, left/right arrow keys, backspace, and then your usual phone pad entry).  Tap the 3 line icon and the text you copied earlier is pasted into the text display area of this app.  Then hit the green tick and it gets pasted into the field you first double clicked on in the web page.
    I hope that helps? 
    BTW, doesn't matter what orientation the screen is in using this method, just that the screen is folded flat back on the phone to hide the qwerty keyboard.
    Message Edited by hyde_tds on 28-Aug-2009 12:06 PM

  • How can I set firefox t o allow cut, copy and paste?

    I am needing to cut info from a college course homepage I am teaching and paste it into another course I am teaching. How can I cut, copy and paste in mozilla firefox?

    See:
    *http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard
    *https://addons.mozilla.org/firefox/addon/allowclipboard-helper/
    You can use the keyboard if the buttons on the web page aren't working.
    * Copy: Ctrl+C or Ctrl+Insert
    * Paste: Ctrl+V or Shift+Insert
    * Cut: Ctrl+X or Shift+Delete

  • With PS 7  create new  Place two objects on the new file  then you may cut copy and paste Cs2  create new  place two object on the new file Cut is not available how does one cut and paste in new file

    With PS 7
    create new
    Place two objects on the new file
    then you may cut copy and paste
    Cs2
    create new
    place two object on the new file
    Cut is not available how does one cut and paste in new file

    If your using File>Place then photoshop cs2 creates what's known as Smart Objects, which photoshop 7 didn't have.
    In photoshop cs2 you can rasterize the smart objects and that should make the Cut function available.
    Select both placed layers, right click on the area to the right of the tumbnail and select Rasterize Layers.
    If in photoshop cs2 you to Help>Photoshop Help and look under Layers>Smart Objects, that should give you a good overview of what smart objects are.

  • How to restrict Cut, Copy and Paste to a Local Clipboard.

    I need to stop any information being copied from my application to other applications such as Word. Is there any way to make sure that all GUI components that support cut, copy and paste use a local clipboard so that I can then control which Flavor's I allow to be cut, copied or pasted?

    What system doesn't allow screen shots? Tell my mobile phone camera that it mustn't take a pic of the screen.
    Anyway, I'd mess with KeyListeners or KeyBindings and suppress STRG+C where you don't want to allow copying. I have never done this, but that would be my first approach.

  • Since downloading 29.0.1 I can no longer cut, copy and paste. So frustrating!!!

    I often copy and paste items into website forums with no problem. However, since I upgraded to 29.0.1 I can no longer do that and it's so frustrating. I have tried doing the extra steps of clicking on your copy and paste items but that doesn't help. I even tried uploading the AllowClipboard Helper but that didn't work either. I never needed that add-on in the past.
    This is ridiculous.
    How do I revert back to version 28? It worked fine but you just had to go ahead and "fix" it and I hate the new version. I was able to download the Classic Theme Restorer which helped a lot but some things I could not make like the version 28.

    karen,
    You don't need that user.js file any longer for those cut, copy, and paste preferences.
    There is a Classic Theme Restorer support thread over here. <br />
    http://forums.mozillazine.org/viewtopic.php?f=48&t=2773133&start=1500 <br />
    They'll be able to help you get rid of that orange Firefox button, which isn't needed if you have the Menu Bar showing.

  • On the Firefox drop down menu for Firefox 4, the tab for cut, copy and paste is not highlighted. Is there another way for me to include this on the Firefox start page?

    I have Firefox 4. In the Firefox drop down menu, there is an option to cut, copy and paste but it is not highlighted. Please tell me how to highlight this link. Or is there a way to have a cut copy and paste tab?

    Those links in the Edit menu are only highlighted if there is something to do:<br />
    Paste should be enabled if the clipboard has data placed on it by a previous Copy or Cut and you have set focus on a text area or field that allows to paste that data.
    Copy works if some text is selected.

  • Envy 17-j020us, cannot cut/copy and paste within file explorer

    I can cut/copy and paste url's and text from word, etc, but I am unable to cut/copy and paste files within file explorer windows. I have tried running malwarebytes and virus programs. HP support has tried remote access to find the problem unsuccessfully. Is there any other option besides doing a factory reset or restore point? Thanks in advance for any help.
    This question was solved.
    View Solution.

    Hi jdavis33811,
    Have you tried all three methods of cutting and pasting? Using the keyboard shortcuts CRTL-X and CTRL-V, right click the file and selecting cut and then using the file explorer ribbon / File menu.
    If you have tried all three the next thing to try is a Clean Boot to see if something is in the background blocking the command. A clean boot loads Windows with minimal software and drivers. This Microsoft Support link will show you how to do it.
    Once you have performed the clean boot try all three methods of cutting and pasting. If it works the next step is going back to msconfig (see Microsoft link above) and enable half of the services you shutoff to do the Clean Boot. Then try cutting and pasting again. Keep enabling half of the remaining services until you can't cut and paste then disable half of the services you just enabled. Do this until you pinpoint what service caused the issue.
    If after all that you are still having a problem then the next step would backing up your files onto an external hard drive or USB flash drive and then doing a full System Recovery.
    Please click “Accept as Solution ” if you feel my post solved your issue.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Thank you,
    BHK6
    I work on behalf of HP

  • How can I copy and paste a URL address?

    How can I copy and paste a URL address?

    Do you use chrome? Just double tap on the link and you will get the cut/copy options.
    All we have to decide is what to do with the time that is given to us - J.R.R. Tolkien

  • Cut, Copy and Paste not working Photoshop CC

    Cut, Copy and Paste are not working in Photoshop CC.
    I tried resetting my tools and preferences, using edit > purge, reinstalling Photoshop CC and reinstalling OSX. Nothing has worked! Help!

    For about 2 weeks I had this problem and today I fixed it!
    Didn't fancy doing a Reset of Firefox as I'd only just done one a few months ago, manually.
    Basically, I uninstalled ZoneAlarm. I've been a ZoneAlarm fan for years but the software just got worse and worse and for about a year this weird thing pops up while I'm in Firefox by pressing CTRL Enter or something, it's like ZoneAlarm has put some kind of layer between me and the browser.
    Anyway, uninstalled it, it rebooted and did a scandisk which did find and fix a few errors too, so could also be that.
    But I'm happy without ZA now as I've found a better one called Online Armour... non of that sneaky trying to install toolbars in your browser rubbish of ZA.
    Hope this helps!
    I can't tell you how good it feels to have copy & paste fully working again!

  • Re: Cut, Copy and Paste

    Hi Ronald,
    I am not an expert on this but I can tell you how I would
    start to approach this task.
    First, create menu commands for cut copy and paste, and
    map short-cut keys to them.
    When I got a cut or copy command, I would call the clipboard
    methods defined on WindowSystem (p. 545 in Display Library
    manual for Release 2). Same thing for paste. At least
    it seems to me that this is what you want to do -- move
    objects to and from the clipboard.
    There are also methods for finding the focus in various
    widgets but I bet you (or someone else) can find them! :-)
    Hope this helps,
    Geoff

    I wonder why the Windows Look and feel doesn't just put a "cut, copy, paste, clear and select all" menu as default for JTextFields and areas. When you use AWT, you get that for free.
    Anyways, read above, but I will add that you can build your menu with the cut copy and paste actions of the JTextField object ...
    Read this document for the actions provided by JTextComponents ...
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#commands
    If you use these actions, you don't have to reinvent the wheel and implement them yourself.

  • Cut,copy and paste functions using the mouse

    Hi.
    I'm a new mac owner and have read that I should be able to do the above. Is that correct, and if so how can I get my mouse to cut, copy and paste text. I can do it through edit but am unable to do so by right clicking.
    Thanks for any help in advance.

    Works fine in TextEdit and Pages - select text by clicking-and-holding and dragging the mouse across it, releasing, then right or control-clicking to bring up the contextual menu which includes these functions. (If you just right-click in TextEdit it will highlight just that word and bring up the menu). It doesn't work in, for example, Safari when entering text as in this forum or reading a web page.

  • How can I copy and Paste in the newly converted PDF to WORD?

    How can I copy and paste in the newly converted document?  I can save it to any Word format and cut within it, but not paste what I just cut or copy and paste.

    Try copying all of the content in your Word document to a new document, then see if you can selectively copy and paste.
    Let us know if that helps!
    -David

  • How do I copy and paste from one page or file to another page or file - on the same screen?

    How do I copy and paste from one page or file to another - on the same screen?

      Open both of your images in the Editor. Click on the image you want to copy and press Ctrtl+A (select all) followed by Ctrl+C (copy) then click the tab for your other image and press Ctrl+V (paste)
    Alternatively click on your background image then simply drag the second image from the photo/project bin and drop it into the main editor workspace on top of the background image. Use the move tool to position and the corner handles of the bounding box to scale.

  • The edit button disappears when I have the link window open, so how do I copy and paste address for email link?

    When I want to create a link to a web page in an email, I click the "link" icon and a window appears asking for the address. But simultaneously, the "edit" function and all other functions disappear from the Firefox toolbar. With no edit, how can I copy and paste the address? I have tried highlighting the address and dragging it into the window, but it won't drop into the window.
    I have resorted to copying the address to a document and then pasting it into the link window, but there must be a less cumbersome way.

    You see the orange (on Linux gray) Firefox button if the Menu Bar is hidden.<br />
    You can make the Menu bar visible via View > Toolbars, also accessible via Firefox > Options.<br />
    If you need to access the hidden Menu bar then press F10 or hold down the Alt key to make the Menu Bar appear temporarily.<br />
    * View > Toolbars : [X] Menu Bar

Maybe you are looking for