How to get the path of the selected Jtree node for deletion purpose

I had one Jtree which show the file structure of the system now i want to get the functionality like when i right click on the node , it should be delete and the file also deleted from my system, for that how can i get the path of that component
i had used
TreePath path = tree.getPathForLocation(loc.x, loc.y);
but it gives the array of objects as (from sop)=> [My Computer, C:\, C:\ANT_HOME, C:\ANT_HOME\lib, C:\ANT_HOME\lib\ant-1.7.0.pom.md5]
i want its last path element how can i get it ?

Call getLastSelectedPathComponent() on the tree.

Similar Messages

  • How to get file path in the form \\filer01\dir\index.htm

    Hi,
    after selecting a file using the FileChooser dialog, i would like to convert the file path like "H:\index.htm" into a form like "\\filer01\dir\index.htm".
    On my system, the logical device name H:\ is mapped to a directory on a file server "filer01".
    Is there any possibility to do this conversion?
    Thanks in advance.

    hi,
    i dont think java has a way of figuring out the actual mappings for a drive, you can retrive all drives that are present using the following code
    File [] roots = File.listRoots();
    then you could just iterate through the roots some of which may be mapped (but you cant figure out which is mapped and which is not).
    So i guess the best way to do it is to have a Properties file with key,value mappings. for eg
    h:\\, \\file01\dir\..
    and then read the value from the Properties file, now if you want this for accessing a resource across the network you dont require to get the actual mapping, you can still use the mapped drive as you would use a unmapped drive.
    hope this helpz
    cheerz
    ynkrish

  • How to get the path when i select a directory or a file in a JTree

    How to get the path when i select a directory or a file in a JTree

    import java.lang.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.HeadlessException;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Iterator;
    * @author Frederic FOURGEOT
    * @version 1.0
    public class JTreeFolder extends JPanel {
    protected DefaultMutableTreeNode racine;
    JTree tree;
    protected JScrollPane scrollpane;
    final static int MAX_LEVEL = 1; // niveau max de descente "direct" dans l'arborescence
    * Sous-classe FSNode
    * @author Frederic FOURGEOT
    * @version 1.0
    private class FSNode extends DefaultMutableTreeNode {
    File file; // contient le fichier li� au noeud
    * Constructeur non visible
    private FSNode() {
    super();
    * Constructeur par initialisation
    * @param userObject Object
    FSNode(Object userObject) {
    super(userObject);
    * Constructeur par initialisation
    * @param userObject Object
    * @param newFile File
    FSNode(Object userObject, File newFile) {
    super(userObject);
    file = newFile;
    * Definit le fichier lie au noeud
    * @param newFile File
    public void setFile(File newFile) {
    file = newFile;
    * Renvoi le fichier lie au noeud
    * @return File
    public File getFile() {
    return file;
    public JTree getJTree(){
         return tree ;
    * Constructeur
    * @throws HeadlessException
    public JTreeFolder() throws HeadlessException {
    File[] drive;
    tree = new JTree();
    // cr�ation du noeud sup�rieur
    racine = new DefaultMutableTreeNode("Poste de travail");
    // cr�ation d'un noeud pour chaque lecteur
    drive = File.listRoots();
    for (int i = 0 ; i < drive.length ; i++) {
    FSNode node = new FSNode(drive, drive[i]);
    addFolder(drive[i], node); // on descend dans l'arborescence du lecteur jusqu'� MAX_LEVEL
    racine.add(node);
    // Gestion d'evenement sur JTree (on �coute les evenements TreeExpansion)
    tree.addTreeExpansionListener(new TreeExpansionListener() {
    public void treeExpanded(TreeExpansionEvent e) {
    // lorsqu'un noeud est ouvert
    // on descend dans l'arborescence du noeud jusqu'� MAX_LEVEL
    TreePath path = e.getPath();
    FSNode node = (FSNode)path.getLastPathComponent();
    addFolder(node);
    ((DefaultTreeModel)tree.getModel()).reload(node); // on recharche uniquement le noeud
    public void treeCollapsed(TreeExpansionEvent e) {
    // lorsqu'un noeud est referm�
    //RIEN
    // alimentation du JTree
    DefaultTreeModel model = new DefaultTreeModel(racine);
    tree.setModel(model);
         setLayout(null);
    // ajout du JTree au formulaire
    tree.setBounds(0, 0, 240, 290);
    scrollpane = new JScrollPane(tree);
         add(scrollpane);
         scrollpane.setBounds(0, 0, 240, 290);
    * Recuperation des sous-elements d'un repertoire
    * @param driveOrDir
    * @param node
    public void addFolder(File driveOrDir, DefaultMutableTreeNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    addFolder(driveOrDir, node, 0);
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Recuperation des sous-elements d'un repertoire
    * (avec niveau pour r�cursivit� et arr�t sur MAX_LEVEL)
    * @param driveOrDir File
    * @param node DefaultMutableTreeNode
    * @param level int
    private void addFolder(File driveOrDir, DefaultMutableTreeNode node, int level) {
    File[] fileList;
    fileList = driveOrDir.listFiles();
    if (fileList != null) {
    sortFiles(fileList); // on tri les elements
    // on ne cherche pas plus loin que le niveau maximal d�finit
    if (level > MAX_LEVEL - 1) {return;}
    // pour chaque �l�ment
    try {
    for (int i = 0; i < fileList.length; i++) {
    // en fonction du type d'�l�ment
    if (fileList[i].isDirectory()) {
    // si c'est un r�pertoire on cr�� un nouveau noeud
    FSNode dir = new FSNode(fileList[i].getName(), fileList[i]);
    node.add(dir);
    // on recherche les �l�ments (r�cursivit�)
    addFolder(fileList[i], dir, ++level);
    if (fileList[i].isFile()) {
    // si c'est un fichier on ajoute l'�l�ment au noeud
    node.add(new FSNode(fileList[i].getName(), fileList[i]));
    catch (NullPointerException e) {
    // rien
    * Recuperation des sous-elements d'un noeud
    * @param node
    public void addFolder(FSNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    for (int i = 0 ; i < node.getChildCount() ; i++) {
    addFolder(((FSNode)node.getChildAt(i)).getFile(), (FSNode)node.getChildAt(i));
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Tri une liste de fichier
    * @param listFile
    public void sortFiles(File[] listFile) {
    triRapide(listFile, 0, listFile.length - 1);
    * QuickSort : Partition
    * @param listFile
    * @param deb
    * @param fin
    * @return
    private int partition(File[] listFile, int deb, int fin) {
    int compt = deb;
    File pivot = listFile[deb];
    int i = deb - 1;
    int j = fin + 1;
    while (true) {
    do {
    j--;
    } while (listFile[j].getName().compareToIgnoreCase(pivot.getName()) > 0);
    do {
    i++;
    } while (listFile[i].getName().compareToIgnoreCase(pivot.getName()) < 0);
    if (i < j) {
    echanger(listFile, i, j);
    } else {
    return j;
    * Tri rapide : quick sort
    * @param listFile
    * @param deb
    * @param fin
    private void triRapide(File[] listFile, int deb, int fin) {
    if (deb < fin) {
    int positionPivot = partition(listFile, deb, fin);
    triRapide(listFile, deb, positionPivot);
    triRapide(listFile, positionPivot + 1, fin);
    * QuickSort : echanger
    * @param listFile
    * @param posa
    * @param posb
    private void echanger(File[] listFile, int posa, int posb) {
    File tmpFile = listFile[posa];
    listFile[posa] = listFile[posb];
    listFile[posb] = tmpFile;

  • How do i get the path of the file selected for opening in JFileChooser

    hi
    I need to get the path of the file selected for opening or saving in the JFileChooser dialog box.Is there any method available.if not how do i get that?
    Thanks and Regards
    Saminathan.

    don't know if its the best/only way, but you could use the getSelectedFile() method in JFileChooser which returns a file and then use the getAbsolutePath() file method

  • How to get the Path of the Current File using Import & Export File -Reg.

    Dear all,
    I have a mega (big) doubt. I have manually inserted the Figures from the figure folders. Now i need, fully automated. So How can I get the Figure path
    Example :
    PMString path = "E://development/Figures/";
    now i checked, How many subFolders is there in "path", get the All Subfolders and check to the Article Name.
    Example
    Article Name == subFolder name then get the Files from the SubFolders(E://development/Figures/ChapterF/*.eps files").
    now I paste the Document using to For Loop.
    Please any one can suggest me, How can We get the Path in SDK.
    Note:
    Should I have to create the relative path by myself?
    No method supplied in SDK to do this directly?
    Please I need a help of this Query as soon as posible.
    Thanks & Regards
    T.R.Harihara SudhaN

    http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/input_file.asp?frame=true
    When a file is uploaded, the file name is also submitted. The path of the file is available only to the machine within the Local Machine security zone. The value property returns only the file name to machines outside the Local Machine security zone. See About URL Security Zones for more information on security zones.
    i need to know on how to get the compelete path /directory of the filename
    using <input type="file"> tag You can't. Its a security thing.
    is there any other way to get an input file from a local host aside from <input type="file"> tag?No. Not using just html.
    You could always go into activex components, but thats different again.
    Cheers,
    evnafets

  • How to get the Path of the WebDynpro page

    Hi All,
    Can any one say how to get the path of the JSPDynPage ina Portlet in Portal Application.
    Becoz i have to display that Page in another JSPDynPagee
    Thanks in Advance....

    Hi,
    You can call your JSPDynPage component by calling the URL as:
    http://localhost:50000/irj/servlet/prt/portal/prtroot/YourApplicationName.YourComponentName
    Check this:
    Calling portal component
    Greetings,
    Praveen Gudapati
    [Points are welcome for helpful answers]

  • How to get the path of the image stored in sap??

    Hi All
    The problem is
    While making an entry in standard there is a field called documents through which we attach our images in sap.
    How to get the path of the image stored with the corresponding order so that the image can be displayed while we are creating a report.
    I know how to upload the image while creating a report using docking control.
    I am not able to get the path of the image stored...
    Please Help
    Thanks in advance..
    Pooja

    I am not aware of exactly which tables are used for storing the attached doc. details, but we have worked in the similar requiremnent.
    What you can do is .... before uploading the image to any order, try swich on the SQL trace ST05 and after upload switch off.
    The log will display what are the tables involved while storing the image. And you can easily find out the image location.

  • How to get two parameters in the same line of selection screen?

    hello
    i need to get my selection csreen like bellow.
    r1 radiobuttion  -some space --p1 parameter
    i should not get the parameter in the next line of  radiobuttion.
    how to get two parameters in the same line of selection screen?

    hi....
    modify the following code
    it will work
    SELECTION-SCREEN BEGIN OF BLOCK SL1 WITH FRAME TITLE TEXT-003.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 10(15) TEXT-001
                     FOR FIELD P1.
    SELECTION-SCREEN POSITION POS_LOW.
    PARAMETERS : P1 TYPE   C USER-COMMAND R2 RADIOBUTTON GROUP R2 DEFAULT 'X',
      P2 TYPE SCARR-CARRNAME,
      P3 TYPE CHAR1 RADIOBUTTON GROUP R2.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK SL1.

  • How to get absolute path of a form within the Forms

    Aslam o Alikum (Hi)
    How to get absolute path of a form within the Forms 6i or 9i
    For example
    i am running a from "abc.fmx" from C:\myfolder directory
    can i get the form path 'C:\myfolder' by calling any any function from "abc.fmb"

    There is no direct call that will always work. What you need to do is call get_application_property(current_form). This may have the full path in it, depending on if that path was defined when the form was launched. If there is no path, then you need to use TOOL_ENV.GETVAR to read the Forms<nn>PATH and the ORACLEPATH, parse those out into individual directories and then check for the FMX in each.
    I already have some code to do all this for you see:
    http://www.groundside.com/blog/content/DuncanMills/Oracle+Forms/?permalink=4A389E73AE26506826E9BED9155D2097.txt

  • Difficult: Drag and Drop: how to get the path of the drag-source ??

    I have to write an applet, after a "Drag&Drop"-Operation from a MS-Word-document to this applet, the applet is supposed to show the path of the document.
    Does anyone know how to do this ?
    thanks

    http://forum.java.sun.com/thread.jsp?forum=4&thread=300727

  • How to get the path of the web-archive on the local filesystem?? [Apache]

    Hello all,
    Im running a webapplication on a tomcat server.
    I need to find out the path of the web-archive on the local filesystem to access several files.
    How can I do that with out having an instance of HttpRequest or whatever??

    Hello Bruce.
    Please take a look at the following KBase article.  It has a sample that will retrieve the folder structure for a specified Crystal Report template based on the instance name in the file store.  The sample there can be easily modified so that it is based on a specific infoObject id.
    1549728 - How to find the folder structure in the CMC of a report template based on the instance file name in the output file store.
    The KBase can be retrieve from the following link:
    https://bosap-support.wdf.sap.corp/sap/support/notes/1549728
    Please note that the KBase article is retrieved through the Service MarketPlace.
    I hope this helps.
    Regards.
    - Robert

  • How to get the path of the image stored in DMS

    Hi everyone..
    My question is that I have attached an image with an order through transaction jha2n..
    Now my requirement is to get the image in report..
    I know the Logical id in ISM_l_ord class and physical id in ISM_P_Ord class.
    I know that link between image and order is in SKWG_BREL.
    But i am not able to get the path so that i can show the image in docking control.
    pls help to retrive the path of the image stored...
    Thanks
    Pooja

    EpicMaster wrote:Now the problem is when I run the application through the .jar file in the dist/ directory the images simply wont load...
    ..lblProduct.setIcon(new ImageIcon("Resources.zip/res/Product.png"));
    Now the problem is when I Build&Clean the whole project which creates a /dist directory containing the complied and execulatble .Jar file for the application AND a folder called "lib" which contains the Resource.Zip folderThe String based constructor to ImageIcon presumes the String represents a File path. File objects do not work with resources inside Jar or Zip archives, for those, you need an URL. Gain the URL using something like..
    URL urlToImage = this.getClass().getResource("/res/Product.png");

  • How to get the path of the cache directory ?

    Hi everyone,
    I need to get the path of the cache directory to copy files into it (these files are security files that are necessary to encrypt data).
    Maybe there is a jnlp.jar to have object that implements a method getCachePath() ? But I can't find it.
    Any ideas ?. thanks.

    you can find the cache location by finding the location of the jar file you are running from:
    URL resource =
    this.getClass().getClassLoader().getResource("testResource");
    if (resource != null) {
    String s = resource.toString();
    if (s.startsWith("jar:")) {
    int index = s.indexOf("!");
    if (index > 4) {
    String fileurl = s.substring(4,index);
    if (fileurl.startswith("file:")) {
    String path = fileurl.substring(5);
    // now path is the path to the jar file in the cache containing the resource
    /Dietz

  • Displaying the path of the file selected by a FileChooser in a TextField

    I'm just getting started with Swing. I developed a simple dialog box that has two text fields and two buttons. The objective is to open two files using those two buttons. I used FileChooser to select the files. Now, I want to display the path of the selected files in their corresponding TextFields. I use the following code to do that.
    final FileChooser fc1 = new FileChooser();
    final FileChooser fc2 = new FileChooser();
    final TextField tf1 = new TextField();
    final TextField tf2 = new TextField();
    private void button1ActionPerformed(ActionEvent evt)
                int returnVal1 = fc1.showOpenDialog(labelPhpFile);
                if (returnVal1 == JFileChooser.APPROVE_OPTION)
                    File file1 = fc1.getSelectedFile();
                    String fileName1 = file1.getName();               
                    String filePath1 = file1.getPath();
                    tf1.setText(filePath1);
    private void button2ActionPerformed(ActionEvent evt)
                int returnVal2 = fc2.showOpenDialog(labelPhpFile);
                if (returnVal2 == JFileChooser.APPROVE_OPTION)
                    File file2 = fc2.getSelectedFile();
                    String fileName2 = file2.getName();               
                    String filePath2 = file2.getPath();
                    tf2.setText(filePath2);
    }The above code works fine only for the first file. Mean the path of the file selected using fc1 is getting displayed in the tf1 TextField. But, the file selected using fc2 is not getting displayed tf2 TextField. Please help me.
    Thank you :)

    h1. The Ubiquitous Newbie Tips
    * DON'T SHOUT!!!
    * Homework dumps will be flamed mercilessly.
    * Have a quick scan through the [Forum FAQ's|http://wikis.sun.com/display/SunForums/Forums.sun.com+FAQ].
    h5. Ask a good question
    * Don't forget to actually ask a question. No, The subject line doesn't count.
    * Ask once
        - Don't Crosspost!
        - Two people answering one question independantly is a waste of there time.
    * Don't even talk to me until you've:
        (a) [googled it|http://www.google.com.au/] and
        (b) looked it up in [Sun's Java Tutorials|http://java.sun.com/docs/books/tutorial/] and
        (c) read the relevant section of the [API Docs|http://java.sun.com/javase/6/docs/api/index-files/index-1.html] and maybe even
        (d) referred to the JLS (for "advanced" questions).
    * [Good questions|http://www.catb.org/~esr/faqs/smart-questions.html#intro] get better Answers. It's a fact. Trust me on this one.
        - Lots of regulars on these forums simply don't read badly written questions. It's just too frustrating.
          - FFS spare us the SMS and L33t speak! Pull your pants up, and get a hair cut!
        - Often you discover your own mistake whilst forming a "Good question".
        - Many of the regulars on these forums will bend over backwards to help with a "Good question",
          especially to a nuggetty problem, because they're interested in the answer.
    * Improve your chances of getting laid tonight by writing an SSCCE
        - For you normal people, That's a: Short Self-Contained Compilable Example.
        - Short is sweet: No-one wants to wade through 5000 lines to find your syntax errors!
        - Often you discover your own mistake whilst writing an SSCCE.
        - Solving your own problem yields a sense of accomplishment ;-)
    h5. Formatting Matters
    * Post your code between a pair of &#123;code} tags
        - That is: &#123;code} ... your code goes here ... &#123;code}
        - This makes your code easier to read by preserving whitespace and highlighting java syntax.
        - Copy&paste your source code directly from your editor. The forum editor basically sucks.
        - The forums tabwidth is 8, as per [the java coding conventions|http://java.sun.com/docs/codeconv/].
          - Indents will go jagged if your tabwidth!=8 and you've mixed tabs and spaces.
          - Lines longer than 80 characters should be wrapped.
          - Proper indentation illustrates program logic.
    * Post your error messages between a pair of &#123;code} tags:
        - That is: &#123;code} ... errors here ... &#123;code}
        - To make it easier for us to find, Mark the erroneous line(s) in your source-code. For example:
            System.out.println("Your momma!); // <<<< ERROR 1
        - Note that error messages are rendered basically useless if the code has been
          modified AT ALL since the error message was produced.
        - Here's [How to read a stacktrace|http://www.0xcafefeed.com/2004/06/of-thread-dumps-and-stack-traces/].
    * The forum editor has a "Preview" pane. Use it.
        - If you're new around here you'll probably find the "Rich Text" view is easier to use.
        - WARNING: Swapping from "Plain Text" view to "Rich Text" scrambles the markup!
        - To see how a posted "special effect" is done, click reply then click the quote button.
    If you (the newbie) have covered these bases *you deserve, and can therefore expect, GOOD answers!*
    h1. The pledge!
    We the New To Java regulars do hereby pledge to refrain from flaming anybody, no matter how gumbyish the question, if the OP has demonstrably tried to cover these bases. The rest are fair game.

  • I deleted most visited, latest headlines, getting started, yahoo, youtube, apple in mozilla's folder,how to get it back like the first time i installed? thx

    i deleted most visited, latest headlines, getting started, yahoo, youtube, apple in mozilla's folder,how to get it back like the first time i installed? thx

    if you hid the menu bar and the navigation bar simply press the alt button, this will bring back the menu bar and form there you can right click and select which bars you want shown

Maybe you are looking for

  • How to change the background color only for one HTML-Portlet?

    Hi all, I have created a HTML-Portlet in my root-page. The root page have a style: Main-Style. I want to change the background-color only for this one HTML-Portlet: <html> <header><title>Test</title></header> <body bgcolor="#999999"> Test </body> </h

  • Downloading Adobe Photoshop

    I've been trying to download adobe photoshop but it kept saying that adobe is experencing problems and to try again later. I've been trying to download this for a week now but it hasen't worked. What do I do now?

  • Example of creating  ALV double click event that can be used in ANY Program

    Once you get the hang of OO you can really create useful generalized code that can be used in a huge number of situtations. Double click on ALV is often wanted Right  here goes to implement a generalized double click action that returns the row, colu

  • Updated N95 software now cannot install Java apps

    Hi I recently (like yesterday) upgraded my N95 8GB to software version V20.0.016. Restored my content. My Gmail and Opera applications were no longer installed so I downloaded them but cannot install. Every time I try and install software either via

  • Comments are not displaying normally (Ref: TA-20964)

    Status: Investigating Affects: Some users Description: Users have been reporting that their comments are not displaying and have been replaced with a Tagged TOS image. We're currenly working to resolve this issue to get your comments back up as norma