How to display default file icon in Swing listing?

Hi All,
I am developing an application where I need to display all the files under a specific folder. But I need to list the files along with their default icon. Also, I need to open that file on clicking (or double clicking) on that file icon.
I am not able to understand how to do that. I am able to list the files in the GUI, but the rest -- I have no clue how to do it.
Any help/pointer on how to do that would be great for me.
Thanks in advance...

FileSystemView fsv = FileSystemView.getFileSystemView();
Icon icon = fsv.getSystemIcon(myFile);As for opening a file on the double-click, assuming you're using a JList, just add a MouseListener/MouseAdapter to your list, and respond to the click events:
public void mouseClicked(MouseEvent e) {
  if(e.getClickCount() == 2) {
    int index = list.locationToIndex(e.getPoint());
    list.ensureIndexIsVisible(index);
    ListModel dlm = list.getModel();
    Object item = dlm.getElementAt(index);
    // Open the file represented by "item".
}If you need to open the file using the system's default application for that file, use Desktop.open(File).

Similar Messages

  • How to display XML file in java swing

    hi all
    now i do my M.Sc., project on data maining.this time i have one problem,thats i can't display XML file in swing frame.so any one know this plz give me that idea or code.
    Thanks to all.
    RSK

    One way of doing that is to use JDOM...
    u create an xml tree, and then output using XMLOutputter class...it will be displayed in text...im not sure if thats what u want...however, if u do want to represent it visually then u may need to draw a tree...u may use the Graphics2D for that...there are alot of ways to do such thing, and the 2 possibilities arent the best...depends on what u want...elaborate more pls.

  • How to display Pdf file in iPad site

    Hi
    How to display Pdf file in web page which can able to view in iPad safari?
    Thanks,
    Arun

    You can't really.
    You need to use DHTML in the swf-wrapper HTML file, usually a
    division wrapped iFrame, and load the PDF into the iFrame as an
    overlay to the Flash.

  • How to set default file path while downloading alv output

    Hi,
    Can anyone tell me that how to set default file path while downloading the ALV output to system using Local file button on tool bar.
    Please look below screenshots:
    Kindly help me resolve it.
    Thanks in advance.
    Regards,
    Ashutosh Katara

    This information initial value is (maybe) stored in Windows Register (register.exe) at Software\SAP\SAPGUI Front\SAP Frontend Server\Filetransfer -> PathDownload, you can read it thru class CL_GUI_FRONTEND_SERVICES method GET_UPLOAD_DOWNLOAD_PATH and update it thru method REGISTRY_SET_VALUE. (Else there may be some parameter ID to force data, but I'm no longer sure)
    Regards,
    Raymond

  • How to display Doc file format in the JEditPane?

    At this time , JEditPane supports RTF and HTML file format ,but
    Could anyone tell me how to display DOC file format using JEditPane
    or other JTextComponents?
    Thx a lot!
    Caton

    Hi,
    there is no support for doc files (M$ Word?) in Java. You would have to create your own classes for that eventually subclassing JEditorPane, EditorKit, Document etc. As well you'd need your own reader for the doc format.
    The problem I see with that however is that there is nothing such as thedoc file format. Microsoft just saves anything produced by MS Word into files ending with .doc. But, if there is anything such as a .doc file format, it changes more often than the weather in April.
    Ulrich

  • How to display the file status in the status bar?

    Hi all,
    Can anyone tell me how to display the file status in the status bar?
    The file status can consists: the type of the file, the size of the file etc..
    thanx alot..

        class StatusBar extends JComponent {
              JLabel l = new JLabel("ready");
            public StatusBar() {
                  super();
                  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
                  add(l);
              public void setText( String prompt ) {
                   l.setText(prompt);
                   setVisible( true );
            public void paint(Graphics g) {
                  super.paint(g);
        }

  • How to display an status Icon in Table UI web dynpro ABAP?

    Hi Experts ,
    How to display an status Icon ( Traffic light ) in Table UI web dynpro ABAP? can somebody tell with a coding example. also I need to update status on condition so whats the best way?
    Thanks in advance.
    Regards,

    Hi Laeeq,
    click on table cntrol n place it on the screen..
    now click on the icon button n place it in the table control area.. a column of icons get created. name it (say) ICON.
    in the PBO..
    loop at internal table and call module in the loop (say) .
    MODULE ICON_DISP.
    now in the module try the foll code :
    module icon_display output.
    check some condition and assign the icon to the variable icon_r
      icon_R = 'ICON_GREEN_LIGHT'.
      CALL FUNCTION 'ICON_CREATE'
        EXPORTING
          name                        = ICON_R
        TEXT                        = ' '
        INFO                        = ' '
        ADD_STDINF                  = 'X'
       IMPORTING
         RESULT                      = ICON
      EXCEPTIONS
        ICON_NOT_FOUND              = 1
        OUTPUTFIELD_TOO_SHORT       = 2
        OTHERS                      = 3
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      endmodule.
    where icon(35) and icon_r(35) type c .
    hope this helps u..
    Regards
    Aparna

  • How to display flash file in adf pages

    how to display flash file in adf pages need help

    Thanks all,
    It is resolved.
    the code i am using to display a flash is below.
    <f:verbatim>
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version
    =10,0,0,0" width="300" height="300" id="11gR1_aniH_grey" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="false" />
    <param name="wmode" value="transparent" />
    <param name="movie" value="mx2004demo.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#4d5c64" />     
    <embed src="../Images/mx2004demo.swf" quality="high" width="300" height="300" name="mx2004demo.swf" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false"
    type="application/x-shockwave-flash" wmode="transparent"
    pluginspage="http://www.adobe.com/go/getflashplayer" />
         </object>
    </f:verbatim>

  • How to display XSL file to ASPX in dreamweaver

    Hi,
    Just wondering how to display XSL file in ASPX page?
    I normally do it in ASP page by using server behaviour XSLT transformation and bind it to ASP page and this works very well.
    Now I am trying to use the same method and using ASPX page this time but this time there is no option from server behaviour where I can bind it to my ASPX.
    Can someone help or perhaps let me know where I can find the information how to do it?
    Thanks,
    Rush O

    You mean you want to see the XML source?
    You need to replace the characters '<' and '&' with corresponding entities '&lt;' and '&amp;'. You can use replaceAll, but do the ampersands first.
    Then I suggest you probably want to put them in a <PRE> block.

  • How to display RTF file and .doc file in JTextPane

    How to display RTF file and .doc file in JTextPane??

    Duplicate post
    http://forum.java.sun.com/thread.jsp?forum=57&thread=567029&tstart=0&trange=30

  • How to connect autocad file to java swing

    hi,
    plz immediately tell me how to connect autocad file to java swing .
    plz help me
    it is very urgent

    Hi there
    See if the link below helps you out.
    Click here to view
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • How to revert to the default file icon for Illustrator CS4

    Hey everyone,
    It has been a few months now and I've searched most forums on how to fix this issue, but sadly, It seems the problem isn't that common. I'm using a Windows 7 machine and have installed the Adobe Master CS4 suite.
    The problem is that I can't seem to revert the illustrator file icon (how .ai files appear in the explorer) back to its original image. The image below shows you what the .ai files look like in my computer. I was hoping if there's someone who could help rectify this issue.
    Much thanks!
    Var
    p.s. I've tried the default file association tool, and have also tried switching back and forth between .ai's default program, but I still get this ugly file icon.

    This is what an Illie file icon normally looks like.
    I'm using CS3 on a Mac.
    If I understand you right you want to be able to see a thumbnail og the file's content.
    As long as you have saved your file with pdf compatability you will be able to see such a thumbnail in the Finder when you have your Finder window set as Columns and click on the file's icon. You will also see a thumbnail if you use Bridge.
    However saving Illie files with pdf compatability increases their weight enormously, so I usually don't unless there's a special reason for doing so.

  • How to display text file in  swing

    hello,
    I have screen where user enters batch number and number.
    when key is pressed a list is displayed on the screen.how to do this and how to relate my actionlistener with the function that generates the list...

    Hi,
    It is simple. Just create a button and add it to the action listener as button.addActionListener(this);
    Your class should extend ActionListener. and also there should be a method named - actionPerformed(ActionEvent avt) in your class
    Now inside this method, just compare the action as:
    if(avt.getSource()==button)
    // in this method, hjust take your file contents and display it on the same window, or create a new Frame here and display it in that window.
    If you want to display the file contents in the same window, then do the following.
    Declare a public JLabel variable for the class and create the JLabel along with the other components as usual but without giving any values. Now in the action part of the button, read the file contents in a string variable, and set the string to the jlabel as folows:
    label.setText(string);
    Hope it helps,
    Cochu.

  • How to display pdf file in windows phone 8 silver light application?

    Hi,
    I am developing windows phone 8 silver light application . For my app I want to display pdf files . Is there any default controls to display pdf files ?
    I don't want to display using launchers , I want to display with in the app.
    any help,
    Thanks..
    Suresh.M

    Probably this should give you a fair idea : How to view PDF file inside an Windows Phone application?
    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8

  • Cannot restore default file icons (maybe caused by Vox?)

    In a nutshell, even though I have deleted Vox, the Vox icon appears against all my FLAC files. I have tried the normal way of replacing the file icon (deleting the icon from the Get Info window) without success. In fact I've tried everything I can think of, hence this post!
    I installed Vox as a simple FLAC player and playlist generator when I ran Mavericks and set it up as default player for all non iTunes audio files. All was well until Vox updated itself to a different more bloated app that wanted to take over my computer. So I uninstalled it using AppDelete. However, all my FLAC files have the little Vox orange loudspeaker next to them and I can't find a way to get rid of it. I have tried highlighting the file, opening the Get Info window and deleting the icon there but it will not delete (and Cut is greyed-out in the Edit dropdown). I can paste another icon over it but it will only affect that individual file, not any other audio file - and if I delete that icon the Vox icon is underneath, as though it's the default.
    In the Info window I have said that all FLAC files should be opened with a different app (Cog) and indeed Cog is now the system FLAC player. But the icons are still the Vox icons!
    Importantly, in a normal Finder window, all the FLAC files display the proper default icon (musical note in a grey square). It's if I display the files from the Document or Download stacks in the dock that the Vox icon is shown. But it's always shown in the Get Info window.
    Obviously this is not a major issue: everything still works without a problem. But I am annoyed that Vox has been able to burrow into my system in this way and want it all cleaned up!
    Thank you for any help you might be able to give. I'm running Yosemite 10.10 (as my sig may say something different!)

    I found the answer to this with help from the people at MacBB. I used a free app called LiteIcon which did the job very neatly for me. I also tried using OnyX and Cocktail but neither of them worked.

Maybe you are looking for

  • General Computer Question

    Hello,  I am about to buy a "bare-bones" new computer, and would like recommendations on what hardware to fit it with.  I will be using it 90% of the time to burn DVDs from Prem. Pro.CS 3 and Encore CS 3.  What I would like to know is 1.) Processor,

  • Calendar Repeatedly stops syncing

    BB Z10 STL100-3 10.2.0.429 Outlook 2007 Only 1 Calendar on Outlook, nothing in personal calendar on phone. Calendar quits syncing - all else works.  IT resets the connection and everything works for a few days. Then I lose the calendar sync again. Th

  • I want to sign up with firefox so I can log in

    I'm trying to build an account with firefox.

  • Setting Up Roland A-Pro Control surfaces with Logic

    I have struggled with Logic Pro 8.0.3 and a new Roland A-500Pro midi keyboard which was reputed to be "easy to configure with a Mac". Despite many discussions with a Roland help person (he tried very hard), The A-Pro control maps provided just don't

  • "The store may be busy." Always.

    I used to frequently get the message "Could not complete the iTunes Store request. The store may be busy. Check your internet connection or try again later." when I tried to get to the iTunes Music Store. I mean, I probably could only load the store