How to display all the files that are selected using JFile chooser

please hepl me i m posting my code here.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class browser extends JFrame
String curDir;
JLabel statusbar;
public browser()
super("File Chooser Test Frame");
setSize(1050,600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
curDir = System.getProperty("user.dir") + File.separator;
statusbar = new JLabel("Output of your button choice goes here!");
Container c = getContentPane();
c.setLayout( null );
JButton openButton = new JButton("Browse file");
JButton dirButton = new JButton("Pick Dir");
JButton resetButton = new JButton("Reset");
JButton submitButton = new JButton("Submit");
final JTextArea tf = new JTextArea(100,50);
final JList l1 = new JList("list");
tf.setEditable(true);
// add the open FILE chooser
openButton.addActionListener(new ActionListener()
     public void actionPerformed(ActionEvent ae)
     JFileChooser chooser = new JFileChooser(curDir);
     chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
     chooser.setMultiSelectionEnabled(true);
//Java 1.6 can use FileNameExtensionFilter class
// FileFilter filter=new FileNameExtensionFilter("HTML file","htm","html")
// chooser.addChoosableFileFilter(filter);
//Prior versions must use external extension of FileFilter class (ie ExtFilter)
//ExtFilter requires separate compile to enable choosable selection
     String[] html = new String[] {"htm","html","xhtml"};
     int option = chooser.showOpenDialog(browser.this);
     if (option == JFileChooser.APPROVE_OPTION)
     File[] sf = chooser.getSelectedFiles();
     String filelist = "nothing";
     try
     if (sf.length > 0) filelist = sf[0].getCanonicalPath();
     for (int i = 1; i < sf.length; i++)
     {filelist += ", " + sf[i].getCanonicalPath();
tf.setText("our choices" + filelist);
     catch (IOException evt) {System.out.println("Exception: "+evt);}
statusbar.setText("Your choices: " + filelist );
// String[] text = new String[100];
//getChars(0,100,text[],0);
l1.setText("your choices \n" + filelist);
     else {statusbar.setText("You cancelled!");}
// add the open DIRECTORY chooser
dirButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
JFileChooser chooser = new JFileChooser(curDir);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     chooser.setMultiSelectionEnabled(false);
int option = chooser.showOpenDialog(browser.this);
if (option == JFileChooser.APPROVE_OPTION)
File[] sf = chooser.getSelectedFiles();
String filelist = "nothing";
try
if (sf.length > 0) filelist = sf[0].getCanonicalPath();
for (int i = 1; i < sf.length; i++)
          {filelist += ", " + sf[i].getCanonicalPath();}
     catch (IOException evt) {System.out.println("Exception: "+evt);}
statusbar.setText("You chose " + filelist);
     else {statusbar.setText("You cancelled!");}
System.out.println("Example of ZIP file creation.");
// Specify files to be zipped
String[] filesToZip = new String[1];
filesToZip[0] = "filelist";
byte[] buffer = new byte[18024];
// Specify zip file name
String zipFileName = "example.zip";
try {
ZipOutputStream out =
new ZipOutputStream(new FileOutputStream(zipFileName));
// Set the compression ratio
out.setLevel(Deflater.DEFAULT_COMPRESSION);
// iterate through the array of files, adding each to the zip file
for (int i = 0; i < filesToZip.length; i++) {
System.out.println(i);
// Associate a file input stream for the current file
FileInputStream in = new FileInputStream(filesToZip);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filesToZip[i]));
// Transfer bytes from the current file to the ZIP file
//out.write(buffer, 0, in.read(buffer));
int len;
while ((len = in.read(buffer)) > 0)
out.write(buffer, 0, len);
// Close the current entry
out.closeEntry();
// Close the current file input stream
in.close();
// Close the ZipOutPutStream
out.close();
catch (IllegalArgumentException iae) {
iae.printStackTrace();
catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
catch (IOException ioe)
ioe.printStackTrace();
c.add(openButton);
c.add(dirButton);
c.add(statusbar);
c.add(resetButton);
c.add(submitButton);
//c.add(tf);
c.add(l1);
Insets insets = c.getInsets();
Dimension size = openButton.getPreferredSize();
openButton.setBounds(745 + insets.left,115 + insets.top, size.width, size.height);
size = dirButton.getPreferredSize();
dirButton.setBounds(755 + insets.left,165 + insets.top, size.width, size.height);
size = statusbar.getPreferredSize();
statusbar.setBounds(755 + insets.left,215 + insets.top, size.width, size.height);
size = resetButton.getPreferredSize();
resetButton.setBounds(755 + insets.left,265 + insets.top, size.width, size.height);
size = submitButton.getPreferredSize();
submitButton.setBounds(755 + insets.left,465 + insets.top, size.width, size.height);
size = tf.getPreferredSize();
tf.setBounds(25 + insets.left,5 + insets.top, size.width + 150, size.height + 430);
size = l1.getPreferredSize();
l1.setBounds(25 + insets.left,5 + insets.top, size.width + 150, size.height + 430);
setSize(1000,800);
setVisible(true);
public static void main(String[] args)
new browser();

Start by defining "display". Then continue by reading this:
http://forum.java.sun.com/help.jspa?sec=formatting

Similar Messages

  • On Windows 7, neither my quicktime or iTunes will start. This started after I installed the newest update. All the files that are needed are there. I recently updated Quicktime to see if that would work, but it didn't.

    This started after I installed the newest update. All the files that are needed are there. I just updated Quicktime to see if that would work, but it didn't. I looked through some other discussions like this, and found out that all of my files are correct. Some people are saying that they needed to remove Filebot, but I can't find that on my computer. Help, please?

    This started after I installed the newest update. All the files that are needed are there. I just updated Quicktime to see if that would work, but it didn't. I looked through some other discussions like this, and found out that all of my files are correct. Some people are saying that they needed to remove Filebot, but I can't find that on my computer. Help, please?

  • How can I populate my PC HD with all the files that are currently on my iPod Classic?

    I think I've changed PCs three times since I've had my iPod Classic 80 gb.
    I think because of this, I have lost copies of files on my PC along the way (probably some of them remained in the earlier PCs and never made it to my current PC) although everything still seems to be on my iPod. So, I often get the message "Cannot locate file."
    Is there a way to populate my current PC with all the files I have on my iPod?
    Simply syncing my iPod doesn't seem to do the trick.
    Thanks for the help!

    You cannot use an iPod backup to restore to an iPad, nor can you use an iPad backup to restore to an iPod.
    Some apps support data syncing through iCloud, but this feature needs building into the app by the developer. If your app doesn't support this, then I believe there is no way to transfer the data between your two devices.

  • Need to process the records that are selected using checkbox in an ALV

    Hi ..
    I am displaying some data in an ALV using the Parent-child relation, the parent records has a check box which is input enabled.
    On click of a button on the toolbar, i need the checked records to be fetched and processed.
    Please help me on how to fetch the records that are checked..
    Thanks,
    Derek

    Hello Derek,
    Is ALV created using OOPS or using conventional FM?
    If you are making use of OOPS technique, then call this method:
    CALL METHOD <grid_name>->get_selected_rows.
    BR,
    Vishal.

  • ITunes not displaying all synced files that are on my iPhone.

    All,
    I am having an issue that I did not see here.
    First, ever since the last iTunes upgrade (the one prior to the latest upgrade that added iTunes match), I have had problems with album artwork displaying on my iPhone. My efforts to solve that issue by deleting and then re-syncing tracks without artwork created another issue: Duplicate songs on my iPhone. The strange thing is, when the iPhone is connected to iTunes and I click "Music" under iPhone, the track list displayed in iTunes shows no duplicates. However, if I navigate on my iPhone (even while connected to my computer), it shows duplicates of several songs. The duplicates appear to be the ones that I tried to delete and then replace to show the artwork.
    I have just done a "restore" on my iPhone to try to resolve the this issue since there apparently is no way to clear the duplicates in iTunes (remember - the duplicate tracks are not displaying). I will see if this solves the issue. Does anyone know what is happening here, and most importantly, how to prevent this from happening again? This is very annoying!

    All,
    I am having an issue that I did not see here.
    First, ever since the last iTunes upgrade (the one prior to the latest upgrade that added iTunes match), I have had problems with album artwork displaying on my iPhone. My efforts to solve that issue by deleting and then re-syncing tracks without artwork created another issue: Duplicate songs on my iPhone. The strange thing is, when the iPhone is connected to iTunes and I click "Music" under iPhone, the track list displayed in iTunes shows no duplicates. However, if I navigate on my iPhone (even while connected to my computer), it shows duplicates of several songs. The duplicates appear to be the ones that I tried to delete and then replace to show the artwork.
    I have just done a "restore" on my iPhone to try to resolve the this issue since there apparently is no way to clear the duplicates in iTunes (remember - the duplicate tracks are not displaying). I will see if this solves the issue. Does anyone know what is happening here, and most importantly, how to prevent this from happening again? This is very annoying!

  • How to display all the files name in same folder inside a JTable?

    Currently i am doing an LAN P2P application (similar to KazAa) which is have a function to search files and list out files name after searched found. I am planning to list all the searched file names in JTable. I am having problem to list the files name on a table field. Can anybodu help : ) ? Please

    I don't understand what your problem is so I'll just refer you to the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]How to Use Tables.

  • Cannot upload because all the playlists that are selected..

    Can someone please help me!! What does it mean when i plug my ipod in.. and it says "Cannot update because all of the playlists selected for updating no longer exisit..? Even though I have all my playlists on the side and everything?
    I DONT GET IT ..! RESPOND ASAP!! please please

    If you have deleted a playlist, it will still try to update it untill you tell it not to. In iTunes, go to iTunes>Preferences and click on the iPod tab. There, you should be able to uncheck the playlist that it's trying to update.

  • How to get the complete path of the file that is selected using FormFile

    i m working on struts..
    i hv used FormFile like
    <html:file property="xsdpath" value="Browse" />
    need to get the whole path that i will select using browse button
    for example d:\foldername\filename.java
    but FormFile Api has a method getFileName(); which returns the filename, for getting the absolute path wat has to be done.
    please reply bak soon
    thanks in advance

    here i use formfile <html:file> just to allow the
    user to select a xml file .
    so i need to get the whole path of the selectedfile
    to parse the xml file.No you dont.
    You would definitely benefit from further reading on
    file upload.
    <html:file> tag renders an HTML <input> element of
    type file.
    When a user uploads a file, this file is sent as a
    stream of data, which a program (jsp/servlet) on the
    server, reads and stores the data back in the form
    of a file on the server.
    Any server program that needs to parse the file,
    should do so on the file stored on the server.
    There's no point in knowing the absolute path of the
    file on the client machine. If a server program can
    parse a file on the client machine, why upload the
    file in first case ? Get the drift ?
    i also want to show my user the path he hadselected.
    If you have such a requirement, then yes.
    But it sounds weird to me. If you see my response
    above, you will realize that the server has a copy of
    the client's file uploaded and then parsed. What if
    the client has changed his file after upload ?
    cheers,
    ram.I also have a requirement to get the whole filepath of the file selected and place this information into a table. From FormFile I can only retreive the absolute filename
    Any suggestions would be helpful.
    Thanks, dam

  • How can i see the  files that  are  suppose to eb backed up on my time capsule

    I have   a  aple time  capsule, which  i think i  was able to back up my imac  on, but   i cannot  view  these  files,  all i get  when i go into the  time capsle  is liek a screen shot  of  finfer  ,   i cannot  find  actual  files  like my  music or  pictures in the  time capsule,  any  suggesions  be  fantastic, thankyou

    You might want to review the Time Machine Tutorial, and perhaps browse Time Machine - Frequently Asked Questions.

  • How can I see the files that are attached to appointments in outlook

    I store files in my appointments in Outlook on my work server that contain travel details, meeting agendas etc. I need to be able to access these on my ipad yet I can't find any way of making them come across to iCal.

    You might want to review the Time Machine Tutorial, and perhaps browse Time Machine - Frequently Asked Questions.

  • How do you change the fields that are displayed on the email preview list after a search?

    How do you modify the fields that are displayed in the mail preview list in the center column of Mac mail after you conduct a search of your email?   All of a sudden the displayed fields changed on me whenever I do a search in mail.   When I have not filtered my email with a search, the default field shown in bold at the top of each message's preview is the "From" field.   However, when I do a search this changes to the "To" field.   Can anyone help?   Thanks, ccarey

    ipicus
    But why would you want this?
    iTunes is responsible for the File Management, let it get on with it, you do your organisation in the iTunes window. And everything you need to do, you can do via the iTunes Window. Want to find the file of a track quickly? Right click on it in the iTunes Window and select Show File: A finder window pops open with the file already selected.
    Regards
    TD

  • HT4796 How can I take the files that were migrated from my PC to my Mac and add all those files to my current user instead of having 2 users?

    How can I take the files that were migrated from my PC to my Mac and add all those files to my current user instead of having 2 users? Having to log out just to sign in on a different user to access the files is absurd.
    Do I make all the files sharable to all the NOW users on the mac then just delete the files? Or can i erase my account that I made when starting up my new mac and then just use the one with the transferred files?
    I just dont want to have to og in and out of 2 different accounts .. Help please.         
    -Nina

    Sorry. /Users is a folder path. It would be similar to C:\Users (if that exists on Windows).
    So, in the Finder, select Computer from the Go menu.
    You'll see Macintosh HD, double-click that to open it.
    In there you'll see several folders. One is Users. That is where all the user Home folders exist. Select the other account's home folder and go to step 3.
    If you have any more confusion, please stop and ask. We'll get there.
    If you feel more comfortable, you can just log into that other account and move the files into /Users/Shared.
    Then, log into the account you wish to use and copy the files from the Shared folder and paste them into your Home folder, wherever they belong, Documents, Music, Pictures, etc.  That just takes a little more work. Transferring them into Shared, and then copying into your home sets the permissions on the files so that you won't have a problem accessing them later. The steps I provided just prevent you from having to do the double move, since you are not going to use the old account once you are done.
    Quick unix shorthand. If someone gives you a file path that begins with a /, that means the root of the hard drive, ie Macintosh HD (if you haven't renamed it). The path separator in unix is /, not \.
    A path that starts with ~/ means your Home folder, the one inside /Users named with your account name.

  • HT1351 Whether or not I sync items on iTunes to my ipod, I cannot eject the ipod because a message keeps coming up and saying that my ipod cannot be ejected because it contains files that are being used by another application. How do I fix this?

    I just got an ipod classic 7th generation a couple days ago and I'm having a heck of a time with it. My latest problem is that with media on iTunes, I cannot eject the ipod because it says that it cannot be ejected because it contains files that are being used by another application. What application is this, and what do I do about it?

    Hi newipoduser,
    Here are some possible solutions:
    Do you use musicmatch jukebox on your computer? If you do, you have to go into task manager on windows and end process mim.exe. It interferes with disconnecting ext devices
    Empty your "trash/recycle bin."
    If that doesn't work, try quitting all your programs, especially music-type programs, basically things that look for mp3's etc.
    if that doesn't work, "log off" then "log on" and that should refresh/purge your OS system.
    Finally, you can restart your computer.
    Hope one of these helps!
    Cheers,
    GB

  • My iMac holds my main iTunes account.  How do I find out a list of all the devices that are authorized from this computer?

    My iMac holds my main iTunes account and it shows 4 devices are authorized to play iTunes.  I can only name 3.  How do I find out a list of all the devices that are authorized from this computer?

    I don't believe this is possible, but you can deauthorize all your computers and start over if you are concerned.
    See here
    Best of luck

  • I understand that many versions of any pictures are still on my computer (Masters???).  If I have a final I like, how do I delete all the others that are taking up space?

    I understand that many versions of any pictures are still on my computer (Masters???).  If I have a final I like, how do I delete all the others that are taking up space?  I have already put the originals into albums, edited them, and renamed them.  Can I/should I delete all other versions located in Masters, I think?  If I want to keep events, but want them to include the newly edited albums, can I delete the specific event and somehow bring the photos used in the album into a new event.  Understand iPhoto just keeps space or manages photos, so how can I have events that include the edited pix and clean up disk space.  Thanks.
    iPhoto 11 v9.4.2
    using Lion, updated, on iMac Pro.

    It's very simple. If you want to use iPhoto, just let it manage things as it does. Other than that: Export from iPhoto and delete the image from iPhoto. That will remove the master and all versions.
    If space is an issue... use an external disk.
    Don't change anything in the iPhoto Library Folder via the Finder or any other application. iPhoto depends on the structure as well as the contents of this folder. Moving things, renaming things, deleting them or otherwise making changes will prevent iPhoto from working and could even cause you to damage or lose your photos.
    Regards
    TD

Maybe you are looking for