Jtree, Double Click to open a file

Here is what I have so far:
tree.addMouseListener(new MouseAdapter(){
            public void mouseClicked(MouseEvent evt){
                if (evt.getClickCount()==2){
                    TreePath tp = tree
                            .getClosestPathForLocation(evt.getX(), evt.getY());
                    File file = (File)tp.getLastPathComponent();
                    // open the file here
                    if(file.isFile() && file.exists()){
                        System.out.format("You double clicked %s", file.toString());
                        //---->What goes here?
        });I've searched the internet and found a few examples that don't work. Anyhow if a person clicks on an image, it should open the image, if they click on a txt document it should open the text document. Any clues on how to implement that would be fantastic.

Thanks that seems to work. I can open .txt documents without a problem. However images don't open and .html pages open and then immediately close. Any ideas?
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;.
tree.addMouseListener(new MouseAdapter(){
            public void mouseClicked(MouseEvent evt){
                if (evt.getClickCount()==2){
                    TreePath tp = tree
                            .getClosestPathForLocation(evt.getX(), evt.getY());
                    File file = (File)tp.getLastPathComponent();
                    // open the file here
                    if(file.isFile() && file.exists()){
                        System.out.format("You double clicked %s", file.toString());
                        try {
                            Desktop.getDesktop().open(file);
                        } catch (IOException ex) {
                            System.out.println("File Error: Unable to open");
                            Logger.getLogger(FileTree.class.getName()).log(Level.SEVERE, null, ex);
        });

Similar Messages

  • Windows Server 2008 R2 clients can't double click to open Office files

    Let me start by saying I don't know too much about Server 2008.
    I have Server set up so desktop clients (Windows 7 Pro 64-bit) can log in as their user on their own machines.  On two of the client machines (mine and my bosses, I have admin rights on everything) a couple funny things are happening:
    1.  Can't open a Word or Excel file by double clicking the icon on the desktop.  Error is as follows:
    Excel
    Microsoft Excel cannot access the file 'C:\Users\(username)\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.XLSB'.  There are several possible reasons:  The file name or path does not exist.  The file is being used by another program. 
    The workbook you are trying to save has the same name as a currently open workbook.
    Word
    The file Normal.dotm cannot be opened because there are problems with the contents.
    and then
    Word cannot open this document template. (C:\Users\(username)\...\AVWiz14s.dotm)
    and then
    Word cannot open the existing file. (Normal)
    and then Word stops responding.
    Note that I can open these documents normally from the start menu.  I have determined this error has something to do with the server because I have tried a bunch of stuff on the internet, including an Excel hotfix, which did nothing.
    2.  Desktop icons flicker, rearrange themselves, and even disappear completely at times.  I do not know what causes this, but I do believe this is a server issue.
    3.  I get recycle bin errors every time I log in, and every time I try to delete anything:
    The Recycle Bin on \\intecserver\Office Employee Files\kneureuter\My Documents\My Videos is corrupted.  Do you want to empty the Recycle Bin for this drive?
    Sometimes I get that error for 3-4 different directories.
    What I've tried:
    I tried reinstalling Office, and that made no difference.
    I have the drive from the server "Office Employee Files" mapped to network drive Y:.  I can open that and go to my account folder on there, navigate to "Desktop" and open the files from there, but not on the physical desktop on my
    computer.
    These files aren't shortcuts on the desktop, their permanent home is on the desktop.
    Just to reiterate, if I moved these files into a folder on the desktop, they will open fine.  If I open them from within Excel or Word, they open fine.  If I open them from the server drive mapped onto my terminal, they open fine.  Just can't
    open them by double-clicking the file if it is directly on the desktop.  Any ideas?
    I logged onto my account from a different computer and double-clicking to open the files worked fine on that computer.  Both computers running Windows 7 Pro 64-bit and Office 2010 Pro.  So that limits it to this machine and my bosses machine.
    Since you can't create a shortcut for something on the desktop, I created a new folder on the desktop and put the files in that folder.  From there I created a shortcut and put that on the desktop.  That worked!
    However, that's just a band-aid.  I need to fix this problem sooner than later. 
    Anyone have any ideas?  Thanks!

    Hi AxEheaD15,
    If  the Desktop or the My Documents folder is redirected to a network location, Office applications may exhibit  the similar issues .
    For details please refer to following link:
    http://support.microsoft.com/kb/2816253/en-us
    Best Regards
    Elton Ji
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Can't double click to open PDF files

    Within the past two weeks I'm getting this odd error where I can't open a PDF file by double clicking it. I get an error saying "This action is only valid for products that are already installed"
    I have Reader 8.1.2. installed. I CAN open a PDF file when I open up Adobe Reader and then browse and select the file from the File Menu. I just can't double click to open any more. Very annoying.
    I tried uninstalling and reinstalling the Reader, but I'm getting the same error.
    Any help is much appreciated!

    Hi AxEheaD15,
    If  the Desktop or the My Documents folder is redirected to a network location, Office applications may exhibit  the similar issues .
    For details please refer to following link:
    http://support.microsoft.com/kb/2816253/en-us
    Best Regards
    Elton Ji
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Did the double click to open a file or folder go away with the Magic Mouse?

    I see that you can set up the right or left "secondary click" and when you click o a folder or file you get the menu to open, etc. But I really perfer to just double click on a file or folder to open it. I see there is a "Double-Click" option at the top of the preferences, but it doesn't seem to do anything. I am on an iMac running 10.6.7
    Thanks in advance for your help.
    Cindy Davis

    Okay, I am officially embarrassed. I thought I had changed enough things around to see if I could get this to work. I had the “Double-Click’ in the preferences set to the far right to be “fast,” the same way I have “Tracking”and “Scrolling,” and those two work fine.  I decided to move the slider to the left a bit and it now works. So, if anyone else has this problem – here’s the solution!
    Cindy

  • Double click to open .sql files with sql developer on mac osx

    hi,
    I am trying to double click a .sql file and open it with SQL Developer on Mac OSX lion. I have associated .sql files to SQL Developer. On clicking the file it opens the SQL developer application but does not open the actual .sql file. Any ideas?
    Thanks

    Hello,
    Did you find any solution to your problem ? My SQL Developer worked fine and could open additional SQL files. Now it only opens the first one when starting SQL Developer. Additionnal files cannot be opened. Even running sqldeveloper.exe from command line with a SQL file as parameter doesn't help.
    I'm on Windows 7, 64 bit, but the environment may not necessarily be the cause.
    Regards
    -- Alwin

  • Acrobat 8.1.3 requires two double clicks to open a file

    Our agency has a VB app that uses adobe to pull up files routinely (for many employees I support they use this app to pull up dozens of documents a day).
    Use to be that when you want to pull up a PDF file from the VB app you double clicked once and the PDF came right up. Now you double click and it brings adobe to the forefront (if not already started) or it will just sit there in the background (if adobe was already started before), and then you have to go back to the VB application and double click on the document name again before it will pull up in the Adobe program in a second adobe window. Only staff with the 8.1.3 update have this issue, those with 8.1.2 do one double click and the document comes right up.

    I would recommend going to the Help>Repair and then repeating with Help>Updates. I am assuming the process is the same on the MAC as the PC.

  • InDesign crashes every time you double click to open an .indd file on Windows system

    InDesign crashes every single time you double click to open an InDesign file and has done so since replacement of the original version of InDesign introduced in the Creative Cloud launch.  Does anyone else have this problem?  I'd say it was unique to my system if I hadn't experienced the issue repeatedly on several different systems now.  You have to relaunch InDesign which then opens the file from recovery, so it saw the file you tried to launch in the first place.  This leads me to believe the problem lies with the file association registry of InDesign inside Windows systems.  I find it unbelievable that this problem still exists and remains unreported and that a solution hasn't been implemented by Adobe to rectify the issue.
    The double click is a fundamental tenant of opening files on a Windows system in the same way a single click is on a Mac.  Does InDesign crash ever time a Mac user clicks to open their files, I think not.
    Anyone got any ideas other than the obvious which is Adobe actually got their figure out and fixed it.
    Cheers,
    Pat Doyle

    Hi Michael,
    I'll give it a go.  Don't really like messing with the registry on Windows boxes.  Yes you can do it, but it can end up being a case of the operation was a success, but the patient died.
    Just was rather hoping someone else had already experienced this problem and posted the registry tweak.  Didn't want spend hours reinventing the wheel.  Not because I'm lazy, but I have so many demands on my time that resolving a minor issue that effects me only seems like it should be pretty low priority.
    The system I'm using is brand new, but the problem seems to have followed me regardless which may indicate that it is seated in my synchronization information somehow.  Really don't know how that could happen as I'm not an Adobe engineer or have the remotest idea where to even start looking.  So I think I'll mark your suggestion as the "Answer" and just learn to live with it.
    Windows eh! Can't live with - can't live without it.  I'm sure Mac can be just as temperamental. Just have to chalk this one up as being just another ghost in the machine.
    Thanks for all the advice you have kindly offered, much appreciated.
    Cheers,
    Pat Doyle

  • Unable to double-click or drag/drop files to open.

    I'm running Photoshop CC 64 on a Windows 7 64 machine and am only able to open files in Photoshop by going to File->Open. Double-clicking from Explorer doesn't work and i can not drag/drop files into the open application window or taskbar icon. Right clicking on files and selecting "Open with" also doesn't work.
    I checked file associations and made sure to choose CC 64. If I right click on the shortcut and choose "Run As Administrator" which I have to do in order to get files to open between Lightroom and Photoshop (both need to be Run As Administrator), I'm still unable to open from Windows Explorer. However, if I check the box to "Run this program as administrator" in the shortcut's Compatibility tab, I can double-click to open from Explorer but am prompted with a UAC warning every time. Dragging/dropping into the open app still doesn't work.
    Opening between Bridge and PS works as expected so long as both programs are "Run As Administrator"
    Been searching the forums here and seen suggestions of similar but not the same issue, at least not that I've found.
    Anyone else experiencing? Suggested remedies?

    This is an OS permission problem.  Make sure you have ownership of the HD.  Do a web search on how to check.  External HD can be a problem for permission.

  • Have trouble double clicking on a second file to open

    There are really two problems here:
    1)  If I double click on a file, it opens in Illustrator, but it does not open with my default workspace settings.  If I open the file from the file menu, my preferred workspace opens.
    and
    2) If I have one file open, I cannot double click on a second file and have that file open in Illustrator.  I just get the little spinning circle and then it stops.  I can still open a second file from the file/open menu option.
    We are using CS6 and running windows 7.

    Brett,
    The issues which you have mentioned points towards having some permissions issue on the system.
    My suggestion would be to make sure that the user account which are using is Administrator.
    Also, make sure you have full permission on the location mentioned in the document below:
    http://helpx.adobe.com/illustrator/kb/preference-file-location-illustrator.html
    Here are the steps to modify ownership and permissions of folders and files:
      1.       Right-click the file or folder, click Properties, and then click the Security tab.
      2.       Click Advanced, and then click the Owner tab.
      3.       Click Edit, and then do one of the following:
    ·         To change the owner to a user or group that is not listed, click Other users and groups and, inEnter the object name to select (examples), type the name of the user or group, and then click OK.
      ·         To change the owner to a user or group that is listed, in the Change owner to box, click the new owner.
      4.       If you want to take ownership of the contents of the folder, select the Replace owner on sub containers and objects check box.
      5.       Click OK, and then click Yes when you receive the following message:
              You do not have permission to read the contents of directory folder name. Do you want to replace the directory permissions with permissions granting you Full Control?
              All permissions will be replaced if you click Yes.
    Note folder name is the name of the folder that you want to take ownership of.
      6.       Click OK, and then reapply the permissions and security settings that you want for the folder and its contents.
      Additional considerations
       ·         An administrator can take ownership of any file on the computer.
       ·         Assigning ownership of a file or a folder might require you to elevate your permissions using
    Let me know if you need more help on this.
    - Mandhir

  • Error Message when Double-clicking a CS4 InDesign File; Won't Open

    I recently installed CS4, upgrading from CS2. Before installing CS4, I could double-click the icon for the file and it would open in InDesign CS2. After installing CS4, when I double-click an InDesign file icon, I get an error message that Windows cannot open the file and needs to know which program should be used. I check the "Select the program from a list" and a window opens that lists several of the applications I have installed. Neither InDesign versions are on the list, so I "Browse" to the Adobe folder in which both InDesigns reside. I then select a version (it doesn't matter which one; neither work) but then it doesn't appear in the list and my "selection" reverts to the "recommended" Photoshop CS4.
    I can understand if this function has disappeared in CS4, and we now have to open a file using the "open" menu item, but I can't understand why neither verison "sticks" in the "Open With" window.
    Any suggestions? I'm using Windows XP SP2.
    Thanks,
    Lloyd

    That's what I thought. I tried the folder options association trick at http://forums.adobe.com/message/2864550#2864550, which kind of worked.  Now, when I double-click on an InDesign file icon, InDesign CS4 opens,  but the file does NOT open. Looks like I'll have to reinstall, unless  someone has an addition to the solution.
    Thanks!
    Lloyd

  • How can i setup pages to automatically open when double clicked.  Currently when I double click it creates cpgz file and does not open.  The only way to open pages doc is to manually ask to open with pages.

    Currently when I double click it creates cpgz file and does not open.  The only way to open pages doc is to manually ask to open with pages.

    Hi Karen,
    Sounds like OS X has lost the association between Pages and its files.
    Start by quitting Pages, then going to Finder.
    In Finder, locate a .pages file. Click on it (once), then press command-I (eye, not one) to Get Info.
    In the Info window that opens, expand the Open With section.
    In this section, click on the pop-up menu and choose Pages (even if Pages is already shown).
    Click the Change All button to associate all files with the .pages extension with Pages.
    Close the info window.
    Double click any .pages file to check that Pages will now launch and open the file.
    Regards,
    Barry

  • How do I get iTunes to ONLY open in Mini Player? I don't want the entire iTunes interface opening when I double click on an Mp3 file.

    How do I get iTunes to ONLY open in Mini Player? I don't want the entire iTunes interface opening when I double click on an Mp3 file.

    Over 6000 people have downladed the script to get around this after a fashion. Is it still required?

  • No place to Double Click visible on pdf file-after opening a password-protected pdf

    No place to Double Click visible on pdf file-after opening a password-protected pdf

    Thanks Pat for your interest.
    Actually I am using Windows 8 (Not 8.1) and Adobe Reader Version XI (11.0.06)
    Now, the exact problem I am facing is that there are certain types of pdf files I am being sent which are Password pritected (it may not be a necessary condition, i don;t know) and after I have keyed-in the correct password, it flashes the message- "Double-click here to open your file". Now while using the earlier versions of Adobe (or maybe Windows) I used to see a peculiar Pin-shaped object on the screen, double-clicking which used to open the file. That object is somehow missing this time, so I have no place to double-click. Therefore I am not able to open the file.I may add that I have recently moved to Windows 8 from XP, so my knowledge of Windows 8 is not up to mark. Can you please help?

  • When I double click a CS3 Illustrator file in finder, it opens in preview, not in Illustrator CS4.

    When I double click a CS3 Illustrator file in finder, it opens in preview, not in Illustrator CS4.
    Is anyone having this same issue?
    Is there a quick and easy method to convert to CS4.
    I have 4000 ads, 3,000 are from freelancers that are CS3 or CS2.
    Jim Etheridge

    Select a couple of .ai files and Get Info on the files. Go to the Open with line and set it to Adobe Illustrator. When it ask if you want it to do the same for this file type answer yes. The OS is probably seeing the file as a PDF and Preview by default is set to open PDFs.

  • Simply put, I do not like like the new color coding "dots" and I do not like having to press the Command key before double clicking to open files in a new window. How hard would have been to include the old version of these two features?

    Simply put, I do not like like the new color coding "dots" and I do not like having to press the Command key before double clicking to open files in a new window. How hard would have been to include the old version of these two features?

    Apple - Mac OS X - Feedback

Maybe you are looking for

  • Is it legal to sell photos edited in trial and beta verisons of Photoshop?

    I recently downloaded the new CS6 beta version of photoshop and since I am interested in stock photography I was wondering if it's legal and not againts Adobe's rules to sell photos edited in trial and beta versions of Photoshop? I mean, since you ha

  • Windows 7 Boot fails on Mac Pro 1,1 (long-standing issue)

    i am having a long-standing problem on my first generation (1,1) mac pro where i have an installation of Windows 7 "under" boot camp. this installation involved some kind of minor mac hack that involved writing something to ISO and/or a CD Rom and th

  • Opening Word docs in InDesign CS4 (Mac). It keeps crashing.

    Hello everyone. I have just upgraded to CS4 from CS2 (Mac) and I have been having numerous issues with Word and InDesign. When I try downloading a fairly complicated Word file into InDesign CS4 it crashes. But, if I open it in InDesign CS2, it opens

  • E-recruitment-- Requisition Page

    Hi All, I am working on E-recruitment in ECC 6. I have generated report using RCF_GENERATE_URL for the employee( 0001 ) and pasted the link in the browser.the Following error was displayed. 1. How can i solve this error. Logon Error "Logon requires a

  • Help! Total newbie question...

    I want to make a flash form where the viewer/user can watch a video clip of their choice (from a drop-down control or something else if there's a better way). I've found myself totally unable to find our how to do this.  I mean, frankly, I don't even